Merge pull request #37 from covespace/history_message_handler
handle devchat log
This commit is contained in:
commit
a11b38c5a3
10
package.json
10
package.json
@ -30,6 +30,16 @@
|
|||||||
],
|
],
|
||||||
"description": "Select whose llm to use."
|
"description": "Select whose llm to use."
|
||||||
},
|
},
|
||||||
|
"DevChat.maxLogCount": {
|
||||||
|
"type": "number",
|
||||||
|
"default": 20,
|
||||||
|
"description": "Limit the number of prompts to output"
|
||||||
|
},
|
||||||
|
"DevChat.logSkip": {
|
||||||
|
"type": "number",
|
||||||
|
"default": 0,
|
||||||
|
"description": "Skip number prompts before showing the prompt history"
|
||||||
|
},
|
||||||
"DevChat.OpenAI.model": {
|
"DevChat.OpenAI.model": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "gpt-4",
|
"default": "gpt-4",
|
||||||
|
@ -1,13 +1,55 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import DevChat, { LogOptions } from '../toolwrapper/devchat';
|
import DevChat, { LogOptions, LogEntry } from '../toolwrapper/devchat';
|
||||||
import { MessageHandler } from './messageHandler';
|
import { MessageHandler } from './messageHandler';
|
||||||
|
import messageHistory from '../util/messageHistory';
|
||||||
|
|
||||||
|
interface LoadHistoryMessages {
|
||||||
|
command: string;
|
||||||
|
entries: Array<LogEntry>;
|
||||||
|
}
|
||||||
|
|
||||||
export async function historyMessages(message: any, panel: vscode.WebviewPanel): Promise<void> {
|
export async function historyMessages(message: any, panel: vscode.WebviewPanel): Promise<void> {
|
||||||
const devChat = new DevChat();
|
const devChat = new DevChat();
|
||||||
|
|
||||||
const logOptions: LogOptions = message.options || {};
|
const logOptions: LogOptions = message.options || {};
|
||||||
const logEntries = await devChat.log(logOptions);
|
const logEntries = await devChat.log(logOptions);
|
||||||
MessageHandler.sendMessage(panel, { command: 'loadHistoryMessages', entries: logEntries });
|
|
||||||
|
const logEntriesFlat = logEntries.flat();
|
||||||
|
// TODO handle context
|
||||||
|
|
||||||
|
const logEntriesFlatFiltered = logEntriesFlat.map((entry) => {
|
||||||
|
return {
|
||||||
|
date: entry.date,
|
||||||
|
hash: entry.hash,
|
||||||
|
request: entry.request,
|
||||||
|
text: entry.response,
|
||||||
|
user: entry.user,
|
||||||
|
parent_hash: '',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i = 0; i < logEntriesFlat.length; i++) {
|
||||||
|
let entryOld = logEntriesFlat[i];
|
||||||
|
let entryNew = {
|
||||||
|
date: entryOld.date,
|
||||||
|
hash: entryOld.hash,
|
||||||
|
request: entryOld.request,
|
||||||
|
text: entryOld.response,
|
||||||
|
user: entryOld.user,
|
||||||
|
parent_hash: '',
|
||||||
|
};
|
||||||
|
if (i > 0) {
|
||||||
|
entryNew.parent_hash = logEntriesFlat[i - 1].hash;
|
||||||
|
}
|
||||||
|
messageHistory.add(panel, entryNew);
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadHistoryMessages: LoadHistoryMessages = {
|
||||||
|
command: 'loadHistoryMessages',
|
||||||
|
entries: logEntriesFlat,
|
||||||
|
};
|
||||||
|
|
||||||
|
MessageHandler.sendMessage(panel, loadHistoryMessages);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,10 @@ export interface LogEntry {
|
|||||||
date: string;
|
date: string;
|
||||||
request: string;
|
request: string;
|
||||||
response: string;
|
response: string;
|
||||||
context: string[];
|
context: Array<{
|
||||||
|
content: string;
|
||||||
|
role: string;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChatResponse {
|
export interface ChatResponse {
|
||||||
@ -231,9 +234,15 @@ class DevChat {
|
|||||||
|
|
||||||
if (options.skip) {
|
if (options.skip) {
|
||||||
args.push('--skip', `${options.skip}`);
|
args.push('--skip', `${options.skip}`);
|
||||||
|
} else {
|
||||||
|
const skipLogCount = vscode.workspace.getConfiguration('DevChat').get('logSkip');
|
||||||
|
args.push('--skip', `${skipLogCount}`);
|
||||||
}
|
}
|
||||||
if (options.maxCount) {
|
if (options.maxCount) {
|
||||||
args.push('--max-count', `${options.maxCount}`);
|
args.push('--max-count', `${options.maxCount}`);
|
||||||
|
} else {
|
||||||
|
const maxLogCount = vscode.workspace.getConfiguration('DevChat').get('maxLogCount');
|
||||||
|
args.push('--max-count', `${maxLogCount}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
|
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
|
||||||
@ -256,7 +265,8 @@ class DevChat {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.parse(stdout.trim());
|
const stdoutNew = "[" + stdout.replace(/\}\n\]\n\[\n \{\n/g, "}\n],\n[\n {\n") + "]";
|
||||||
|
return JSON.parse(stdoutNew.trim());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.channel()?.error(`Error getting log: ${error}`);
|
logger.channel()?.error(`Error getting log: ${error}`);
|
||||||
logger.channel()?.show();
|
logger.channel()?.show();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user