update devchat, remove anthropic provider
This commit is contained in:
parent
c70364ba3c
commit
ec7de83529
29
package.json
29
package.json
@ -112,27 +112,6 @@
|
|||||||
"order": -1,
|
"order": -1,
|
||||||
"markdownDescription": "Specify the properties for openai provider."
|
"markdownDescription": "Specify the properties for openai provider."
|
||||||
},
|
},
|
||||||
"devchat.Provider.anthropic": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"access_key": {
|
|
||||||
"type": "string",
|
|
||||||
"default": "",
|
|
||||||
"description": "[required*] Specify access key for selected provider."
|
|
||||||
},
|
|
||||||
"api_base": {
|
|
||||||
"type": "string",
|
|
||||||
"default": "",
|
|
||||||
"description": "[optional*] Specify the api base for selected provider. Leave it blank if you want to use default api base."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"access_key"
|
|
||||||
],
|
|
||||||
"additionalProperties": false,
|
|
||||||
"order": -1,
|
|
||||||
"markdownDescription": "Specify the properties for anthropic provider."
|
|
||||||
},
|
|
||||||
"devchat.Model.gpt-3-5": {
|
"devchat.Model.gpt-3-5": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -259,8 +238,7 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "devchat",
|
"default": "devchat",
|
||||||
"enum": [
|
"enum": [
|
||||||
"devchat",
|
"devchat"
|
||||||
"anthropic"
|
|
||||||
],
|
],
|
||||||
"description": "[required*] which provider host this llm model"
|
"description": "[required*] which provider host this llm model"
|
||||||
},
|
},
|
||||||
@ -524,11 +502,6 @@
|
|||||||
"title": "Input OpenAI API Key",
|
"title": "Input OpenAI API Key",
|
||||||
"category": "DevChat"
|
"category": "DevChat"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"command": "DevChat.AccessKey.Anthropic",
|
|
||||||
"title": "Input Anthropic API Key",
|
|
||||||
"category": "DevChat"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"command": "DevChat.AccessKey.DevChat",
|
"command": "DevChat.AccessKey.DevChat",
|
||||||
"title": "Input DevChat Access Key",
|
"title": "Input DevChat Access Key",
|
||||||
|
@ -14,7 +14,7 @@ export function checkDevChatDependency(showError: boolean = true): boolean {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if DevChat is installed
|
// Check if DevChat is installed
|
||||||
const expectVersion = 'DevChat 0.2.7';
|
const expectVersion = 'DevChat 0.2.8';
|
||||||
const devchatVersion = runCommand(`"${devChat}" --version`).toString().trim();
|
const devchatVersion = runCommand(`"${devChat}" --version`).toString().trim();
|
||||||
if (devchatVersion < expectVersion) {
|
if (devchatVersion < expectVersion) {
|
||||||
logger.channel()?.info(`devchat version: ${devchatVersion}, but expect version: ${expectVersion}`);
|
logger.channel()?.info(`devchat version: ${devchatVersion}, but expect version: ${expectVersion}`);
|
||||||
|
@ -6,120 +6,10 @@ import { ApiKeyManager } from '../util/apiKey';
|
|||||||
import { UiUtilWrapper } from '../util/uiUtil';
|
import { UiUtilWrapper } from '../util/uiUtil';
|
||||||
|
|
||||||
|
|
||||||
export async function getValidModels(): Promise<string[]> {
|
|
||||||
const modelProperties = async (modelPropertyName: string, modelName: string) => {
|
|
||||||
const modelConfig = UiUtilWrapper.getConfiguration("devchat", modelPropertyName);
|
|
||||||
if (!modelConfig) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
let modelProperties: any = {};
|
|
||||||
for (const key of Object.keys(modelConfig || {})) {
|
|
||||||
const property = modelConfig![key];
|
|
||||||
modelProperties[key] = property;
|
|
||||||
}
|
|
||||||
if (!modelConfig["provider"]) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
const providerProperty = "Provider." + modelConfig["provider"];
|
|
||||||
const providerConfig = UiUtilWrapper.getConfiguration("devchat", providerProperty);
|
|
||||||
if (providerConfig) {
|
|
||||||
if (providerConfig["access_key"]) {
|
|
||||||
modelProperties["api_key"] = providerConfig["access_key"];
|
|
||||||
}
|
|
||||||
if (providerConfig["api_base"]) {
|
|
||||||
modelProperties["api_base"] = providerConfig["api_base"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!modelProperties["api_key"]) {
|
|
||||||
const providerName = ApiKeyManager.toProviderKey(modelConfig["provider"]);
|
|
||||||
if (!providerName) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
let apiKey = await ApiKeyManager.loadApiKeySecret(providerName);
|
|
||||||
if (!apiKey) {
|
|
||||||
apiKey = await ApiKeyManager.loadApiKeySecret("DevChat");
|
|
||||||
if (!apiKey) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modelProperties["api_key"] = apiKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
modelProperties['model'] = modelName;
|
|
||||||
return modelProperties;
|
|
||||||
};
|
|
||||||
|
|
||||||
let modelList : string[] = [];
|
|
||||||
const openaiModel = await modelProperties('Model.gpt-3-5', "gpt-3.5-turbo");
|
|
||||||
if (openaiModel) {
|
|
||||||
modelList.push(openaiModel.model);
|
|
||||||
}
|
|
||||||
const openaiModel2 = await modelProperties('Model.gpt-3-5-16k', "gpt-3.5-turbo-16k");
|
|
||||||
if (openaiModel2) {
|
|
||||||
modelList.push(openaiModel2.model);
|
|
||||||
}
|
|
||||||
const openaiModel3 = await modelProperties('Model.gpt-4', "gpt-4");
|
|
||||||
if (openaiModel3) {
|
|
||||||
modelList.push(openaiModel3.model);
|
|
||||||
}
|
|
||||||
const claudeModel = await modelProperties('Model.claude-2', "claude-2");
|
|
||||||
if (claudeModel) {
|
|
||||||
modelList.push(claudeModel.model);
|
|
||||||
}
|
|
||||||
const xinghuoModel = await modelProperties('Model.xinghuo-2', "xinghuo-2");
|
|
||||||
if (xinghuoModel) {
|
|
||||||
modelList.push(xinghuoModel.model);
|
|
||||||
}
|
|
||||||
const glmModel = await modelProperties('Model.chatglm_pro', "chatglm_pro");
|
|
||||||
if (glmModel) {
|
|
||||||
modelList.push(glmModel.model);
|
|
||||||
}
|
|
||||||
const erniebotModel = await modelProperties('Model.ERNIE-Bot', "ERNIE-Bot");
|
|
||||||
if (erniebotModel) {
|
|
||||||
modelList.push(erniebotModel.model);
|
|
||||||
}
|
|
||||||
const llama2Model = await modelProperties('Model.llama-2-13b-chat', "llama-2-13b-chat");
|
|
||||||
if (llama2Model) {
|
|
||||||
modelList.push(llama2Model.model);
|
|
||||||
}
|
|
||||||
|
|
||||||
const customModelConfig: any = UiUtilWrapper.getConfiguration('devchat', 'customModel');
|
|
||||||
if (!customModelConfig) {
|
|
||||||
return modelList;
|
|
||||||
}
|
|
||||||
|
|
||||||
const customModels = customModelConfig as Array<any>;
|
|
||||||
for (const model of customModels) {
|
|
||||||
if (!model.model) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const modelProvider = model["model"].split('/')[0];
|
|
||||||
const modelName = model["model"].split('/').slice(1).join('/');
|
|
||||||
|
|
||||||
if (!model["api_key"]) {
|
|
||||||
const providerName = ApiKeyManager.toProviderKey(modelProvider);
|
|
||||||
if (!providerName) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const apiKey = await ApiKeyManager.loadApiKeySecret(providerName);
|
|
||||||
if (!apiKey) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
modelList.push(model["model"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return modelList;
|
|
||||||
}
|
|
||||||
|
|
||||||
regInMessage({command: 'regModelList'});
|
regInMessage({command: 'regModelList'});
|
||||||
regOutMessage({command: 'regModelList', result: [{name: ''}]});
|
regOutMessage({command: 'regModelList', result: [{name: ''}]});
|
||||||
export async function regModelList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
export async function regModelList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
||||||
const modelList = await getValidModels();
|
const modelList = await ApiKeyManager.getValidModels();
|
||||||
|
|
||||||
MessageHandler.sendMessage(panel, { command: 'regModelList', result: modelList });
|
MessageHandler.sendMessage(panel, { command: 'regModelList', result: modelList });
|
||||||
return;
|
return;
|
||||||
|
@ -30,10 +30,126 @@ export class ApiKeyManager {
|
|||||||
return llmModelT.api_key;
|
return llmModelT.api_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getValidModels(): Promise<string[]> {
|
||||||
|
const modelProperties = async (modelPropertyName: string, modelName: string) => {
|
||||||
|
const modelConfig = UiUtilWrapper.getConfiguration("devchat", modelPropertyName);
|
||||||
|
if (!modelConfig) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let modelProperties: any = {};
|
||||||
|
for (const key of Object.keys(modelConfig || {})) {
|
||||||
|
const property = modelConfig![key];
|
||||||
|
modelProperties[key] = property;
|
||||||
|
}
|
||||||
|
if (!modelConfig["provider"]) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const providerProperty = "Provider." + modelConfig["provider"];
|
||||||
|
const providerConfig = UiUtilWrapper.getConfiguration("devchat", providerProperty);
|
||||||
|
if (providerConfig) {
|
||||||
|
if (providerConfig["access_key"]) {
|
||||||
|
modelProperties["api_key"] = providerConfig["access_key"];
|
||||||
|
}
|
||||||
|
if (providerConfig["api_base"]) {
|
||||||
|
modelProperties["api_base"] = providerConfig["api_base"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!modelProperties["api_key"]) {
|
||||||
|
const providerName = ApiKeyManager.toProviderKey(modelConfig["provider"]);
|
||||||
|
if (!providerName) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
let apiKey = await ApiKeyManager.loadApiKeySecret(providerName);
|
||||||
|
if (!apiKey) {
|
||||||
|
apiKey = await ApiKeyManager.loadApiKeySecret("DevChat");
|
||||||
|
if (!apiKey) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modelProperties["api_key"] = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
modelProperties['model'] = modelName;
|
||||||
|
return modelProperties;
|
||||||
|
};
|
||||||
|
|
||||||
|
let modelList : string[] = [];
|
||||||
|
const openaiModel = await modelProperties('Model.gpt-3-5', "gpt-3.5-turbo");
|
||||||
|
if (openaiModel) {
|
||||||
|
modelList.push(openaiModel.model);
|
||||||
|
}
|
||||||
|
const openaiModel2 = await modelProperties('Model.gpt-3-5-16k', "gpt-3.5-turbo-16k");
|
||||||
|
if (openaiModel2) {
|
||||||
|
modelList.push(openaiModel2.model);
|
||||||
|
}
|
||||||
|
const openaiModel3 = await modelProperties('Model.gpt-4', "gpt-4");
|
||||||
|
if (openaiModel3) {
|
||||||
|
modelList.push(openaiModel3.model);
|
||||||
|
}
|
||||||
|
const claudeModel = await modelProperties('Model.claude-2', "claude-2");
|
||||||
|
if (claudeModel) {
|
||||||
|
modelList.push(claudeModel.model);
|
||||||
|
}
|
||||||
|
const xinghuoModel = await modelProperties('Model.xinghuo-2', "xinghuo-2");
|
||||||
|
if (xinghuoModel) {
|
||||||
|
modelList.push(xinghuoModel.model);
|
||||||
|
}
|
||||||
|
const glmModel = await modelProperties('Model.chatglm_pro', "chatglm_pro");
|
||||||
|
if (glmModel) {
|
||||||
|
modelList.push(glmModel.model);
|
||||||
|
}
|
||||||
|
const erniebotModel = await modelProperties('Model.ERNIE-Bot', "ERNIE-Bot");
|
||||||
|
if (erniebotModel) {
|
||||||
|
modelList.push(erniebotModel.model);
|
||||||
|
}
|
||||||
|
const llama2Model = await modelProperties('Model.llama-2-13b-chat', "llama-2-13b-chat");
|
||||||
|
if (llama2Model) {
|
||||||
|
modelList.push(llama2Model.model);
|
||||||
|
}
|
||||||
|
|
||||||
|
const customModelConfig: any = UiUtilWrapper.getConfiguration('devchat', 'customModel');
|
||||||
|
if (!customModelConfig) {
|
||||||
|
return modelList;
|
||||||
|
}
|
||||||
|
|
||||||
|
const customModels = customModelConfig as Array<any>;
|
||||||
|
for (const model of customModels) {
|
||||||
|
if (!model.model) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const modelProvider = model["model"].split('/')[0];
|
||||||
|
const modelName = model["model"].split('/').slice(1).join('/');
|
||||||
|
|
||||||
|
if (!model["api_key"]) {
|
||||||
|
const providerName = ApiKeyManager.toProviderKey(modelProvider);
|
||||||
|
if (!providerName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const apiKey = await ApiKeyManager.loadApiKeySecret(providerName);
|
||||||
|
if (!apiKey) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
modelList.push(model["model"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return modelList;
|
||||||
|
}
|
||||||
|
|
||||||
static async llmModel() {
|
static async llmModel() {
|
||||||
const llmModelT = UiUtilWrapper.getConfiguration('devchat', 'defaultModel');
|
let llmModelT = UiUtilWrapper.getConfiguration('devchat', 'defaultModel');
|
||||||
if (!llmModelT) {
|
if (!llmModelT) {
|
||||||
return undefined;
|
const validModels = await this.getValidModels();
|
||||||
|
if (validModels.length > 0) {
|
||||||
|
await UiUtilWrapper.updateConfiguration('devchat', 'defaultModel', validModels[0]);
|
||||||
|
llmModelT = validModels[0];
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const modelProperties = async (modelPropertyName: string, modelName: string) => {
|
const modelProperties = async (modelPropertyName: string, modelName: string) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user