Merge pull request #16 from covespace/add_config

Add config
This commit is contained in:
boob.yang 2023-05-05 15:02:59 +08:00 committed by GitHub
commit 2b7752608e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 1 deletions

View File

@ -18,6 +18,41 @@
"README.md"
],
"contributes": {
"configuration": {
"title": "DevChat",
"properties": {
"DevChat.llmModel": {
"type": "string",
"default": "OpenAI",
"enum": ["OpenAI"],
"description": "Select whose llm to use."
},
"DevChat.OpenAI.model": {
"type": "string",
"default": "gpt-4",
"description": "Specify llm model",
"when": "DevChat.llmModel == 'OpenAI'"
},
"DevChat.OpenAI.temperature": {
"type": "number",
"default": 0.2,
"description": "Specify llm temperature",
"when": "DevChat.llmModel == 'OpenAI'"
},
"DevChat.OpenAI.stream": {
"type": "boolean",
"default": true,
"description": "Specify llm stream",
"when": "DevChat.llmModel == 'OpenAI'"
},
"DevChat.OpenAI.apiKey": {
"type": "string",
"default": "",
"description": "Open API Key",
"when": "DevChat.llmModel == 'OpenAI'"
}
}
},
"views": {
"explorer": [
{

View File

@ -5,6 +5,7 @@ import { promisify } from "util";
import * as vscode from 'vscode';
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 }> => {
return new Promise((resolve, reject) => {
@ -82,7 +83,28 @@ class DevChat {
args.push(content)
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');
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 devchatConfig = {
llm: llmModel,
OpenAI: {
model: openaiModel,
temperature: openaiTemperature,
stream: openaiStream
}
}
// write to config file
const configPath = path.join(workspaceDir!, '.chatconfig.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, {