reg command to update valid chat models

This commit is contained in:
bobo.yang 2023-09-13 10:08:16 +08:00
parent 16046ec517
commit 650281059c
5 changed files with 37 additions and 12 deletions

View File

@ -644,6 +644,11 @@
"command": "DevChat.InstallCommands", "command": "DevChat.InstallCommands",
"title": "Install slash commands", "title": "Install slash commands",
"category": "DevChat" "category": "DevChat"
},
{
"command": "DevChat.UpdataChatModels",
"title": "Update Chat Models",
"category": "DevChat"
} }
], ],
"menus": { "menus": {

View File

@ -21,7 +21,7 @@ import { FT } from '../util/feature_flags/feature_toggles';
import { getPackageVersion } from '../util/python_installer/pip_package_version'; import { getPackageVersion } from '../util/python_installer/pip_package_version';
import { exec } from 'child_process'; import { exec } from 'child_process';
import { sendCommandListByDevChatRun } from '../handler/regCommandList'; import { sendCommandListByDevChatRun, updateChatModels } from '../handler/regCommandList';
import DevChat from "../toolwrapper/devchat"; import DevChat from "../toolwrapper/devchat";
let indexProcess: CommandRun | null = null; let indexProcess: CommandRun | null = null;
@ -539,6 +539,14 @@ export function registerInstallCommandsCommand(context: vscode.ExtensionContext)
context.subscriptions.push(disposable); 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 ) { export async function addSummaryContextFun(fsPath: string ) {
if (!FT("ask-code-summary")) { if (!FT("ask-code-summary")) {
UiUtilWrapper.showErrorMessage("This command is a beta version command and has not been released yet."); UiUtilWrapper.showErrorMessage("This command is a beta version command and has not been released yet.");

View File

@ -20,6 +20,7 @@ import {
registerAskCodeSummaryIndexStopCommand, registerAskCodeSummaryIndexStopCommand,
registerAddSummaryContextCommand, registerAddSummaryContextCommand,
registerInstallCommandsCommand, registerInstallCommandsCommand,
registerUpdateChatModelsCommand,
} from './contributes/commands'; } from './contributes/commands';
import { regLanguageContext } from './contributes/context'; import { regLanguageContext } from './contributes/context';
import { regDevChatView, regTopicView } from './contributes/views'; import { regDevChatView, regTopicView } from './contributes/views';
@ -52,6 +53,7 @@ function activate(context: vscode.ExtensionContext) {
registerStatusBarItemClickCommand(context); registerStatusBarItemClickCommand(context);
registerInstallCommandsCommand(context); registerInstallCommandsCommand(context);
registerUpdateChatModelsCommand(context);
createStatusBarItem(context); createStatusBarItem(context);
if (FT("ask-code")) { if (FT("ask-code")) {

View File

@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import CommandManager from '../command/commandManager'; import CommandManager from '../command/commandManager';
import { MessageHandler } from './messageHandler'; import { MessageHandler } from './messageHandler';
import { regInMessage, regOutMessage } from '../util/reg_messages'; import { regInMessage, regOutMessage } from '../util/reg_messages';
import { getValidModels } from './regValidModelList';
regInMessage({command: 'regCommandList'}); 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 });
}

View File

@ -6,14 +6,11 @@ import { ApiKeyManager } from '../util/apiKey';
import { UiUtilWrapper } from '../util/uiUtil'; import { UiUtilWrapper } from '../util/uiUtil';
export async function getValidModels(): Promise<string[]> {
regInMessage({command: 'regModelList'});
regOutMessage({command: 'regModelList', result: [{name: ''}]});
export async function regModelList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
const modelProperties = async (modelPropertyName: string, modelName: string) => { const modelProperties = async (modelPropertyName: string, modelName: string) => {
const modelConfig = UiUtilWrapper.getConfiguration("devchat", modelPropertyName); const modelConfig = UiUtilWrapper.getConfiguration("devchat", modelPropertyName);
if (!modelConfig) { if (!modelConfig) {
return undefined; return undefined;
} }
let modelProperties: any = {}; let modelProperties: any = {};
@ -43,25 +40,24 @@ export async function regModelList(message: any, panel: vscode.WebviewPanel|vsco
let modelList : string[] = []; let modelList : string[] = [];
const openaiModel = await modelProperties('Model.gpt-3-5', "gpt-3.5-turbo"); const openaiModel = await modelProperties('Model.gpt-3-5', "gpt-3.5-turbo");
if (openaiModel) { if (openaiModel) {
modelList.push(openaiModel.modal); modelList.push(openaiModel.model);
} }
const openaiModel2 = await modelProperties('Model.gpt-3-5-16k', "gpt-3.5-turbo-16k"); const openaiModel2 = await modelProperties('Model.gpt-3-5-16k', "gpt-3.5-turbo-16k");
if (openaiModel2) { if (openaiModel2) {
modelList.push(openaiModel2.modal); modelList.push(openaiModel2.model);
} }
const openaiModel3 = await modelProperties('Model.gpt-4', "gpt-4"); const openaiModel3 = await modelProperties('Model.gpt-4', "gpt-4");
if (openaiModel3) { if (openaiModel3) {
modelList.push(openaiModel3.modal); modelList.push(openaiModel3.model);
} }
const claudeModel = await modelProperties('Model.claude-2', "claude-2"); const claudeModel = await modelProperties('Model.claude-2', "claude-2");
if (claudeModel) { if (claudeModel) {
modelList.push(claudeModel.modal); modelList.push(claudeModel.model);
} }
const customModelConfig: any = UiUtilWrapper.getConfiguration('devchat', 'customModel'); const customModelConfig: any = UiUtilWrapper.getConfiguration('devchat', 'customModel');
if (!customModelConfig) { if (!customModelConfig) {
MessageHandler.sendMessage(panel, { command: 'regModelList', result: modelList }); return modelList;
return;
} }
const customModels = customModelConfig as Array<any>; const customModels = customModelConfig as Array<any>;
@ -86,6 +82,14 @@ export async function regModelList(message: any, panel: vscode.WebviewPanel|vsco
modelList.push(model["model"]); 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<void> {
const modelList = await getValidModels();
MessageHandler.sendMessage(panel, { command: 'regModelList', result: modelList }); MessageHandler.sendMessage(panel, { command: 'regModelList', result: modelList });
return; return;