From dd1bef553984c529c68b3f0077dc9d80360e9733 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Wed, 13 Sep 2023 10:08:16 +0800 Subject: [PATCH] Add function to update configuration for version 0.9.12 - Added a new function `configUpdateTo_0912` to update the configuration for the 'devchat' extension. - The function retrieves the 'DevChat', 'Api_Key_OpenAI', and 'API_ENDPOINT' configurations and creates a new configuration object. - If the 'Model.gpt-4' configuration does not exist and the new configuration object is not empty, it updates the 'Model.gpt-3-5', 'Model.gpt-3-5-16k', and 'Model.gpt-4' configurations. - The function is called during the activation of the extension. --- src/extension.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index e05edd7..58a77df 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -33,6 +33,43 @@ import { UiUtilWrapper } from './util/uiUtil'; import { UiUtilVscode } from './util/uiUtil_vscode'; import { FT } from './util/feature_flags/feature_toggles'; +async function configUpdateTo_0912() { + const devchatKey = UiUtilWrapper.getConfiguration('DevChat', 'Access_Key_DevChat'); + const openaiKey = UiUtilWrapper.getConfiguration('DevChat', 'Api_Key_OpenAI'); + const endpointKey = UiUtilWrapper.getConfiguration('DevChat', 'API_ENDPOINT'); + + let modelConfigNew = {}; + if (openaiKey) { + modelConfigNew["api_key"] = openaiKey; + } else if (devchatKey) { + modelConfigNew["api_key"] = devchatKey; + } + + modelConfigNew["provider"] = "openai"; + + if (endpointKey) { + modelConfigNew["api_base"] = endpointKey; + } + + const modelConfig1: any = UiUtilWrapper.getConfiguration("devchat", "Model.gpt-3-5"); + const modelConfig2: any = UiUtilWrapper.getConfiguration("devchat", "Model.gpt-3-5-16k"); + const modelConfig3: any = UiUtilWrapper.getConfiguration("devchat", "Model.gpt-4"); + //if (!modelConfig1 && !modelConfig2 && !modelConfig3 && Object.keys(modelConfigNew).length > 0) { + if (Object.keys(modelConfig1).length === 0 && + Object.keys(modelConfig2).length === 0 && + Object.keys(modelConfig3).length === 0 && + Object.keys(modelConfigNew).length > 0) { + // config default gpt models + try { + vscode.workspace.getConfiguration("devchat").update("Model.gpt-3-5", modelConfigNew, vscode.ConfigurationTarget.Global); + vscode.workspace.getConfiguration("devchat").update("Model.gpt-3-5-16k", modelConfigNew, vscode.ConfigurationTarget.Global); + vscode.workspace.getConfiguration("devchat").update("Model.gpt-4", modelConfigNew, vscode.ConfigurationTarget.Global); + } catch(error) { + return; + } + } +} + function activate(context: vscode.ExtensionContext) { ExtensionContextHolder.context = context; @@ -40,6 +77,8 @@ function activate(context: vscode.ExtensionContext) { logger.init(LoggerChannelVscode.getInstance()); UiUtilWrapper.init(new UiUtilVscode()); + configUpdateTo_0912(); + regLanguageContext(); regDevChatView(context);