From 452e8c3757f5b82dcd7f5d3f482ff0d964c43748 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Thu, 14 Sep 2023 20:17:55 +0800 Subject: [PATCH] load api key from command secret and env --- src/extension.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index feb58ce..1c4704d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -39,10 +39,20 @@ async function configUpdateTo_0912() { vscode.workspace.getConfiguration("devchat").update("defaultModel", "gpt-3.5-turbo", vscode.ConfigurationTarget.Global); } - const devchatKey = UiUtilWrapper.getConfiguration('DevChat', 'Access_Key_DevChat'); - const openaiKey = UiUtilWrapper.getConfiguration('DevChat', 'Api_Key_OpenAI'); + let devchatKey = UiUtilWrapper.getConfiguration('DevChat', 'Access_Key_DevChat'); + let openaiKey = UiUtilWrapper.getConfiguration('DevChat', 'Api_Key_OpenAI'); const endpointKey = UiUtilWrapper.getConfiguration('DevChat', 'API_ENDPOINT'); - + + devchatKey = undefined; + openaiKey = undefined; + if (!devchatKey && !openaiKey) { + openaiKey = await UiUtilWrapper.secretStorageGet("openai_OPENAI_API_KEY"); + devchatKey = await UiUtilWrapper.secretStorageGet("devchat_OPENAI_API_KEY"); + } + if (!devchatKey && !openaiKey) { + openaiKey = process.env.OPENAI_API_KEY; + } + let modelConfigNew = {}; if (openaiKey) { modelConfigNew["api_key"] = openaiKey;