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",
|
"description": "Specify llm stream",
|
||||||
"when": "DevChat.llmModel == 'OpenAI'"
|
"when": "DevChat.llmModel == 'OpenAI'"
|
||||||
},
|
},
|
||||||
|
"DevChat.OpenAI.tokensPerPrompt": {
|
||||||
|
"type": "number",
|
||||||
|
"default": 6000,
|
||||||
|
"description": "token for each prompt",
|
||||||
|
"when": "DevChat.llmModel == 'OpenAI'"
|
||||||
|
},
|
||||||
"DevChat.OpenAI.apiKey": {
|
"DevChat.OpenAI.apiKey": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "",
|
"default": "",
|
||||||
|
@ -7,7 +7,7 @@ import * as dotenv from 'dotenv';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
const child = spawn(command, args, options);
|
const child = spawn(command, args, options);
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
@ -25,9 +25,9 @@ const spawnAsync = async (command: string, args: string[], options: any, onData:
|
|||||||
|
|
||||||
child.on('close', (code) => {
|
child.on('close', (code) => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve({code, stdout, stderr });
|
resolve({ code, stdout, stderr });
|
||||||
} else {
|
} else {
|
||||||
reject({code, stdout, stderr });
|
reject({ code, stdout, stderr });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -49,11 +49,12 @@ export interface LogOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface LogEntry {
|
export interface LogEntry {
|
||||||
"prompt-hash": string;
|
hash: string;
|
||||||
user: string;
|
user: string;
|
||||||
date: string;
|
date: string;
|
||||||
message: string;
|
request: string;
|
||||||
response: string;
|
response: string;
|
||||||
|
context: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChatResponse {
|
export interface ChatResponse {
|
||||||
@ -64,19 +65,27 @@ export interface ChatResponse {
|
|||||||
isError: boolean;
|
isError: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class DevChat {
|
class DevChat {
|
||||||
async chat(content: string, options: ChatOptions = {}, onData: (data: string) => void): Promise<ChatResponse> {
|
async chat(content: string, options: ChatOptions = {}, onData: (data: string) => void): Promise<ChatResponse> {
|
||||||
let args = ["prompt"];
|
let args = ["prompt"];
|
||||||
|
|
||||||
if (options.parent) {
|
if (options.parent) {
|
||||||
args.push("-p", options.parent);
|
for (const parent of options.parent) {
|
||||||
|
args.push("-p", parent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (options.reference) {
|
if (options.reference) {
|
||||||
args.push("-r", options.reference.join(","));
|
for (const reference of options.reference) {
|
||||||
|
args.push("-r", reference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (options.header) {
|
if (options.header) {
|
||||||
args.push("-i", options.header.join(","));
|
for (const header of options.header) {
|
||||||
|
args.push("-i", header);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (options.context) {
|
if (options.context) {
|
||||||
args.push("-c", options.context.join(","));
|
args.push("-c", options.context.join(","));
|
||||||
}
|
}
|
||||||
@ -85,29 +94,34 @@ class DevChat {
|
|||||||
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
|
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
|
||||||
// const openaiApiKey = process.env.OPENAI_API_KEY;
|
// 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 openaiModel = vscode.workspace.getConfiguration('DevChat').get('OpenAI.model');
|
||||||
const openaiTemperature = vscode.workspace.getConfiguration('DevChat').get('OpenAI.temperature');
|
const openaiTemperature = vscode.workspace.getConfiguration('DevChat').get('OpenAI.temperature');
|
||||||
const openaiStream = vscode.workspace.getConfiguration('DevChat').get('OpenAI.stream');
|
const openaiStream = vscode.workspace.getConfiguration('DevChat').get('OpenAI.stream');
|
||||||
const llmModel = vscode.workspace.getConfiguration('DevChat').get('llmModel');
|
const llmModel = vscode.workspace.getConfiguration('DevChat').get('llmModel');
|
||||||
|
const tokensPerPrompt = vscode.workspace.getConfiguration('DevChat').get('OpenAI.tokensPerPrompt');
|
||||||
|
|
||||||
const devchatConfig = {
|
const devchatConfig = {
|
||||||
llm: llmModel,
|
|
||||||
OpenAI: {
|
|
||||||
model: openaiModel,
|
model: openaiModel,
|
||||||
|
provider: llmModel,
|
||||||
|
OpenAI: {
|
||||||
temperature: openaiTemperature,
|
temperature: openaiTemperature,
|
||||||
stream: openaiStream
|
stream: openaiStream,
|
||||||
|
"tokens-per-prompt": tokensPerPrompt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// write to config file
|
// write to config file
|
||||||
const configPath = path.join(workspaceDir!, '.chatconfig.json');
|
const configPath = path.join(workspaceDir!, '.chat', 'config.json');
|
||||||
// write devchatConfig to configPath
|
// write devchatConfig to configPath
|
||||||
const configJson = JSON.stringify(devchatConfig, null, 2);
|
const configJson = JSON.stringify(devchatConfig, null, 2);
|
||||||
fs.writeFileSync(configPath, configJson);
|
fs.writeFileSync(configPath, configJson);
|
||||||
|
|
||||||
try {
|
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
|
maxBuffer: 10 * 1024 * 1024, // Set maxBuffer to 10 MB
|
||||||
cwd: workspaceDir,
|
cwd: workspaceDir,
|
||||||
env: {
|
env: {
|
||||||
@ -201,14 +215,14 @@ class DevChat {
|
|||||||
const openaiApiKey = process.env.OPENAI_API_KEY;
|
const openaiApiKey = process.env.OPENAI_API_KEY;
|
||||||
|
|
||||||
try {
|
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
|
maxBuffer: 10 * 1024 * 1024, // Set maxBuffer to 10 MB
|
||||||
cwd: workspaceDir,
|
cwd: workspaceDir,
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
OPENAI_API_KEY: openaiApiKey,
|
OPENAI_API_KEY: openaiApiKey,
|
||||||
},
|
},
|
||||||
}, (partialResponse: string) => {});
|
}, (partialResponse: string) => { });
|
||||||
|
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.error(stderr);
|
console.error(stderr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user