diff --git a/package.json b/package.json index 4bfb2e0..89b1053 100644 --- a/package.json +++ b/package.json @@ -644,6 +644,11 @@ "command": "DevChat.InstallCommands", "title": "Install slash commands", "category": "DevChat" + }, + { + "command": "DevChat.UpdataChatModels", + "title": "Update Chat Models", + "category": "DevChat" } ], "menus": { diff --git a/src/contributes/commands.ts b/src/contributes/commands.ts index b961135..bffa23c 100644 --- a/src/contributes/commands.ts +++ b/src/contributes/commands.ts @@ -21,7 +21,7 @@ import { FT } from '../util/feature_flags/feature_toggles'; import { getPackageVersion } from '../util/python_installer/pip_package_version'; import { exec } from 'child_process'; -import { sendCommandListByDevChatRun } from '../handler/regCommandList'; +import { sendCommandListByDevChatRun, updateChatModels } from '../handler/regCommandList'; import DevChat from "../toolwrapper/devchat"; let indexProcess: CommandRun | null = null; @@ -539,6 +539,14 @@ export function registerInstallCommandsCommand(context: vscode.ExtensionContext) context.subscriptions.push(disposable); } +export function registerUpdateChatModelsCommand(context: vscode.ExtensionContext) { + let disposable = vscode.commands.registerCommand('DevChat.UpdataChatModels', async () => { + updateChatModels(); + }); + + context.subscriptions.push(disposable); +} + export async function addSummaryContextFun(fsPath: string ) { if (!FT("ask-code-summary")) { UiUtilWrapper.showErrorMessage("This command is a beta version command and has not been released yet."); diff --git a/src/extension.ts b/src/extension.ts index 7f18748..e05edd7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,6 +20,7 @@ import { registerAskCodeSummaryIndexStopCommand, registerAddSummaryContextCommand, registerInstallCommandsCommand, + registerUpdateChatModelsCommand, } from './contributes/commands'; import { regLanguageContext } from './contributes/context'; import { regDevChatView, regTopicView } from './contributes/views'; @@ -52,6 +53,7 @@ function activate(context: vscode.ExtensionContext) { registerStatusBarItemClickCommand(context); registerInstallCommandsCommand(context); + registerUpdateChatModelsCommand(context); createStatusBarItem(context); if (FT("ask-code")) { diff --git a/src/handler/regCommandList.ts b/src/handler/regCommandList.ts index e59f8a9..43190a4 100644 --- a/src/handler/regCommandList.ts +++ b/src/handler/regCommandList.ts @@ -2,6 +2,7 @@ import * as vscode from 'vscode'; import CommandManager from '../command/commandManager'; import { MessageHandler } from './messageHandler'; import { regInMessage, regOutMessage } from '../util/reg_messages'; +import { getValidModels } from './regValidModelList'; regInMessage({command: 'regCommandList'}); @@ -48,3 +49,8 @@ export async function sendCommandListByDevChatRun() { } } +export async function updateChatModels() { + const modelList = await getValidModels(); + MessageHandler.sendMessage(existPannel!, { command: 'regModelList', result: modelList }); +} + diff --git a/src/handler/regValidModelList.ts b/src/handler/regValidModelList.ts index 9be0bf5..61f949c 100644 --- a/src/handler/regValidModelList.ts +++ b/src/handler/regValidModelList.ts @@ -6,14 +6,11 @@ import { ApiKeyManager } from '../util/apiKey'; import { UiUtilWrapper } from '../util/uiUtil'; - -regInMessage({command: 'regModelList'}); -regOutMessage({command: 'regModelList', result: [{name: ''}]}); -export async function regModelList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise { +export async function getValidModels(): Promise { const modelProperties = async (modelPropertyName: string, modelName: string) => { const modelConfig = UiUtilWrapper.getConfiguration("devchat", modelPropertyName); if (!modelConfig) { - return undefined; + return undefined; } let modelProperties: any = {}; @@ -43,25 +40,24 @@ export async function regModelList(message: any, panel: vscode.WebviewPanel|vsco let modelList : string[] = []; const openaiModel = await modelProperties('Model.gpt-3-5', "gpt-3.5-turbo"); if (openaiModel) { - modelList.push(openaiModel.modal); + modelList.push(openaiModel.model); } const openaiModel2 = await modelProperties('Model.gpt-3-5-16k', "gpt-3.5-turbo-16k"); if (openaiModel2) { - modelList.push(openaiModel2.modal); + modelList.push(openaiModel2.model); } const openaiModel3 = await modelProperties('Model.gpt-4', "gpt-4"); if (openaiModel3) { - modelList.push(openaiModel3.modal); + modelList.push(openaiModel3.model); } const claudeModel = await modelProperties('Model.claude-2', "claude-2"); if (claudeModel) { - modelList.push(claudeModel.modal); + modelList.push(claudeModel.model); } const customModelConfig: any = UiUtilWrapper.getConfiguration('devchat', 'customModel'); if (!customModelConfig) { - MessageHandler.sendMessage(panel, { command: 'regModelList', result: modelList }); - return; + return modelList; } const customModels = customModelConfig as Array; @@ -86,6 +82,14 @@ export async function regModelList(message: any, panel: vscode.WebviewPanel|vsco modelList.push(model["model"]); } + + return modelList; +} + +regInMessage({command: 'regModelList'}); +regOutMessage({command: 'regModelList', result: [{name: ''}]}); +export async function regModelList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise { + const modelList = await getValidModels(); MessageHandler.sendMessage(panel, { command: 'regModelList', result: modelList }); return;