Get logs of a topic via client
This commit is contained in:
parent
84ef68c500
commit
bebe32fa18
@ -1,4 +1,17 @@
|
||||
import DevChat, { LogEntry, LogOptions } from '../toolwrapper/devchat';
|
||||
import { DevChatClient, ShortLog } from '../toolwrapper/devchatClient';
|
||||
|
||||
export interface LogEntry {
|
||||
hash: string;
|
||||
parent: string | null;
|
||||
user: string;
|
||||
date: string;
|
||||
request: string;
|
||||
response: string;
|
||||
context: Array<{
|
||||
content: string;
|
||||
role: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface LoadHistoryMessages {
|
||||
command: string;
|
||||
@ -41,18 +54,28 @@ OPENAI_API_KEY is missing from your environment or settings. Kindly input your O
|
||||
} as LogEntry;
|
||||
}
|
||||
|
||||
export async function loadTopicHistoryLogs(topicId: string | undefined): Promise<Array<LogEntry> | undefined> {
|
||||
async function loadTopicHistoryLogs(topicId: string | undefined): Promise<Array<LogEntry> | undefined> {
|
||||
if (!topicId) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const devChat = new DevChat();
|
||||
const logOptions: LogOptions = {
|
||||
skip: 0,
|
||||
maxCount: 10000,
|
||||
topic: topicId
|
||||
};
|
||||
const logEntries = await devChat.log(logOptions);
|
||||
|
||||
const dcClient = new DevChatClient();
|
||||
const shortLogs: ShortLog[] = await dcClient.getTopicLogs(topicId, 10000, 0);
|
||||
|
||||
const logEntries: Array<LogEntry> = [];
|
||||
for (const shortLog of shortLogs) {
|
||||
const logE: LogEntry = {
|
||||
hash: shortLog.hash,
|
||||
parent: shortLog.parent,
|
||||
user: shortLog.user,
|
||||
date: shortLog.date,
|
||||
request: shortLog.request,
|
||||
response: shortLog.responses[0],
|
||||
context: shortLog.context,
|
||||
};
|
||||
|
||||
logEntries.push(logE);
|
||||
}
|
||||
|
||||
return logEntries;
|
||||
}
|
||||
|
@ -289,6 +289,35 @@ export class DevChatClient {
|
||||
return res;
|
||||
}
|
||||
|
||||
@timeThis
|
||||
async getTopicLogs(
|
||||
topicRootHash: string,
|
||||
limit: number,
|
||||
offset: number
|
||||
): Promise<ShortLog[]> {
|
||||
const data = {
|
||||
limit: limit,
|
||||
offset: offset,
|
||||
workspace: UiUtilWrapper.workspaceFoldersFirstPath(),
|
||||
};
|
||||
const response = await axios.get(
|
||||
`${this.baseURL}/topics/${topicRootHash}/logs`,
|
||||
{
|
||||
params: data,
|
||||
}
|
||||
);
|
||||
|
||||
const logs: ShortLog[] = response.data;
|
||||
logs.reverse();
|
||||
|
||||
logger
|
||||
.channel()
|
||||
?.debug(`getTopicLogs response data: ${JSON.stringify(logs)}`);
|
||||
|
||||
return logs;
|
||||
}
|
||||
|
||||
|
||||
stopAllRequest(): void {
|
||||
this.cancelMessage();
|
||||
// add other requests here if needed
|
||||
|
Loading…
x
Reference in New Issue
Block a user