Merge pull request #24 from covespace/update_devchat

update to lastest devchat
This commit is contained in:
boob.yang 2023-05-08 09:52:22 +08:00 committed by GitHub
commit 90c75f4d46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 202 additions and 182 deletions

View File

@ -47,6 +47,12 @@
"description": "Specify llm stream",
"when": "DevChat.llmModel == 'OpenAI'"
},
"DevChat.OpenAI.tokensPerPrompt": {
"type": "number",
"default": 6000,
"description": "token for each prompt",
"when": "DevChat.llmModel == 'OpenAI'"
},
"DevChat.OpenAI.apiKey": {
"type": "string",
"default": "",

View File

@ -49,11 +49,12 @@ export interface LogOptions {
}
export interface LogEntry {
"prompt-hash": string;
hash: string;
user: string;
date: string;
message: string;
request: string;
response: string;
context: string[];
}
export interface ChatResponse {
@ -64,19 +65,27 @@ export interface ChatResponse {
isError: boolean;
}
class DevChat {
async chat(content: string, options: ChatOptions = {}, onData: (data: string) => void): Promise<ChatResponse> {
let args = ["prompt"];
if (options.parent) {
args.push("-p", options.parent);
for (const parent of options.parent) {
args.push("-p", parent);
}
}
if (options.reference) {
args.push("-r", options.reference.join(","));
for (const reference of options.reference) {
args.push("-r", reference);
}
}
if (options.header) {
args.push("-i", options.header.join(","));
for (const header of options.header) {
args.push("-i", header);
}
}
if (options.context) {
args.push("-c", options.context.join(","));
}
@ -85,23 +94,28 @@ class DevChat {
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
// const openaiApiKey = process.env.OPENAI_API_KEY;
const openaiApiKey = vscode.workspace.getConfiguration('DevChat').get('OpenAI.apiKey');
let openaiApiKey = vscode.workspace.getConfiguration('DevChat').get('OpenAI.apiKey');
if (!openaiApiKey) {
openaiApiKey = process.env.OPENAI_API_KEY;
}
const openaiModel = vscode.workspace.getConfiguration('DevChat').get('OpenAI.model');
const openaiTemperature = vscode.workspace.getConfiguration('DevChat').get('OpenAI.temperature');
const openaiStream = vscode.workspace.getConfiguration('DevChat').get('OpenAI.stream');
const llmModel = vscode.workspace.getConfiguration('DevChat').get('llmModel');
const tokensPerPrompt = vscode.workspace.getConfiguration('DevChat').get('OpenAI.tokensPerPrompt');
const devchatConfig = {
llm: llmModel,
OpenAI: {
model: openaiModel,
provider: llmModel,
OpenAI: {
temperature: openaiTemperature,
stream: openaiStream
stream: openaiStream,
"tokens-per-prompt": tokensPerPrompt
}
}
// write to config file
const configPath = path.join(workspaceDir!, '.chatconfig.json');
const configPath = path.join(workspaceDir!, '.chat', 'config.json');
// write devchatConfig to configPath
const configJson = JSON.stringify(devchatConfig, null, 2);
fs.writeFileSync(configPath, configJson);