Merge pull request #24 from covespace/update_devchat
update to lastest devchat
This commit is contained in:
commit
90c75f4d46
@ -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": "",
|
||||
|
@ -7,7 +7,7 @@ import * as dotenv from 'dotenv';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
const spawnAsync = async (command: string, args: string[], options: any, onData: (data: string) => void): Promise<{code: number, stdout: string; stderr: string }> => {
|
||||
const spawnAsync = async (command: string, args: string[], options: any, onData: (data: string) => void): Promise<{ code: number, stdout: string; stderr: string }> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(command, args, options);
|
||||
let stdout = '';
|
||||
@ -25,9 +25,9 @@ const spawnAsync = async (command: string, args: string[], options: any, onData:
|
||||
|
||||
child.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
resolve({code, stdout, stderr });
|
||||
resolve({ code, stdout, stderr });
|
||||
} else {
|
||||
reject({code, stdout, stderr });
|
||||
reject({ code, stdout, stderr });
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -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,29 +94,34 @@ 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);
|
||||
|
||||
try {
|
||||
const {code, stdout, stderr } = await spawnAsync('devchat', args, {
|
||||
const { code, stdout, stderr } = await spawnAsync('devchat', args, {
|
||||
maxBuffer: 10 * 1024 * 1024, // Set maxBuffer to 10 MB
|
||||
cwd: workspaceDir,
|
||||
env: {
|
||||
@ -201,14 +215,14 @@ class DevChat {
|
||||
const openaiApiKey = process.env.OPENAI_API_KEY;
|
||||
|
||||
try {
|
||||
const {code, stdout, stderr } = await spawnAsync('devchat', args, {
|
||||
const { code, stdout, stderr } = await spawnAsync('devchat', args, {
|
||||
maxBuffer: 10 * 1024 * 1024, // Set maxBuffer to 10 MB
|
||||
cwd: workspaceDir,
|
||||
env: {
|
||||
...process.env,
|
||||
OPENAI_API_KEY: openaiApiKey,
|
||||
},
|
||||
}, (partialResponse: string) => {});
|
||||
}, (partialResponse: string) => { });
|
||||
|
||||
if (stderr) {
|
||||
console.error(stderr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user