From 1beb011bfa2d9e7ce7ebb6241fa75f0b40839865 Mon Sep 17 00:00:00 2001 From: Jelf Date: Sat, 21 Sep 2024 15:45:36 +0800 Subject: [PATCH] refactor: configuration --- extensions/void/package.json | 397 +++++++++--------- extensions/void/src/SidebarWebviewProvider.ts | 8 +- extensions/void/src/common/sendLLMMessage.ts | 31 +- extensions/void/src/extension.ts | 6 + 4 files changed, 221 insertions(+), 221 deletions(-) diff --git a/extensions/void/package.json b/extensions/void/package.json index 4d6d54b0..972e1d3d 100644 --- a/extensions/void/package.json +++ b/extensions/void/package.json @@ -27,252 +27,233 @@ "ollama" ] }, - "void.anthropic": { + "void.anthropic.apiKey": { + "type": "string", + "description": "Anthropic API key." + }, + "void.anthropic.model": { + "type": "string", + "default": "claude-3-5-sonnet-20240620", + "description": "Choose a model ('claude-3-5-sonnet-20240620' | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307')", + "enum": [ + "claude-3-5-sonnet-20240620", + "claude-3-opus-20240229", + "claude-3-sonnet-20240229", + "claude-3-haiku-20240307" + ] + }, + "void.anthropic.providerSettings": { "type": "object", "properties": { - "model": { + "baseURL": { "type": "string", - "default": "claude-3-5-sonnet-20240620", - "description": "Choose a model ('claude-3-5-sonnet-20240620' | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307')", - "enum": [ - "claude-3-5-sonnet-20240620", - "claude-3-opus-20240229", - "claude-3-sonnet-20240229", - "claude-3-haiku-20240307" - ] + "description": "Use a different URL prefix for API calls, e.g. to use proxy servers." }, - "providerSettings": { + "apiKey": {}, + "headers": { "type": "object", - "properties": { - "baseURL": { - "type": "string", - "description": "Use a different URL prefix for API calls, e.g. to use proxy servers." - }, - "apiKey": { - "type": "string", - "description": "Anthropic API key." - }, - "headers": { - "type": "object", - "description": "Custom headers to include in the requests." - } - } + "description": "Custom headers to include in the requests." } } }, - "void.openai": { + "void.openai.model": { + "type": "string", + "default": "gpt-4o", + "description": "Choose a model ('o1-preview' | 'o1-mini' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106')", + "enum": [ + "o1-preview", + "o1-mini", + "gpt-4o", + "gpt-4o-2024-05-13", + "gpt-4o-2024-08-06", + "gpt-4o-mini", + "gpt-4o-mini-2024-07-18", + "gpt-4-turbo", + "gpt-4-turbo-2024-04-09", + "gpt-4-turbo-preview", + "gpt-4-0125-preview", + "gpt-4-1106-preview", + "gpt-4", + "gpt-4-0613", + "gpt-3.5-turbo-0125", + "gpt-3.5-turbo", + "gpt-3.5-turbo-1106" + ] + }, + "void.openai.apiKey": { + "type": "string", + "description": "OpenAI API key." + }, + "void.openai.providerSettings": { "type": "object", "properties": { - "model": { + "baseURL": { "type": "string", - "default": "gpt-4o", - "description": "Choose a model ('o1-preview' | 'o1-mini' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106')", - "enum": [ - "o1-preview", - "o1-mini", - "gpt-4o", - "gpt-4o-2024-05-13", - "gpt-4o-2024-08-06", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "gpt-4-turbo", - "gpt-4-turbo-2024-04-09", - "gpt-4-turbo-preview", - "gpt-4-0125-preview", - "gpt-4-1106-preview", - "gpt-4", - "gpt-4-0613", - "gpt-3.5-turbo-0125", - "gpt-3.5-turbo", - "gpt-3.5-turbo-1106" - ] + "description": "Use a different URL prefix for API calls, e.g. to use proxy servers." }, - "providerSettings": { + "headers": { "type": "object", - "properties": { - "baseURL": { - "type": "string", - "description": "Use a different URL prefix for API calls, e.g. to use proxy servers." - }, - "apiKey": { - "type": "string", - "description": "OpenAI API key." - }, - "headers": { - "type": "object", - "description": "Custom headers to include in the requests." - }, - "organization": { - "type": "string", - "description": "OpenAI Organization." - }, - "project": { - "type": "string", - "description": "OpenAI project." - }, - "compatibility": { - "type": "string", - "description": "OpenAI compatibility mode. Should be set to `strict` when using the OpenAI API, and `compatible` when using 3rd party providers. In `compatible` mode, newer information such as streamOptions are not being sent. Defaults to 'compatible'.", - "enum": [ - "strict", - "compatible" - ] - } - } + "description": "Custom headers to include in the requests." + }, + "organization": { + "type": "string", + "description": "OpenAI Organization." + }, + "project": { + "type": "string", + "description": "OpenAI project." + }, + "compatibility": { + "type": "string", + "description": "OpenAI compatibility mode. Should be set to `strict` when using the OpenAI API, and `compatible` when using 3rd party providers. In `compatible` mode, newer information such as streamOptions are not being sent. Defaults to 'compatible'.", + "enum": [ + "strict", + "compatible" + ] } } }, - "void.azure": { + "void.azure.deploymentId": { + "type": "string", + "description": "Azure API deployment ID." + }, + "void.azure.resourceName": { + "type": "string", + "description": "Name of the Azure OpenAI resource. Either this or `baseURL` can be used. \nThe resource name is used in the assembled URL: `https://{resourceName}.openai.azure.com/openai/deployments/{modelId}{path}`" + }, + "void.azure.apiKey": { + "type": "string", + "description": "Azure API key." + }, + "void.azure.providerSettings": { "type": "object", "properties": { - "deploymentId": { + "baseURL": { "type": "string", - "description": "Azure API deployment ID." + "description": "Azure API base URL." }, - "providerSettings": { + "headers": { "type": "object", - "properties": { - "apiKey": { - "type": "string", - "description": "Azure API key." - }, - "baseURL": { - "type": "string", - "description": "Azure API base URL." - }, - "resourceName": { - "type": "string", - "description": "Name of the Azure OpenAI resource. Either this or `baseURL` can be used. \nThe resource name is used in the assembled URL: `https://{resourceName}.openai.azure.com/openai/deployments/{modelId}{path}`" - }, - "headers": { - "type": "object", - "description": "Custom headers to include in the requests." - } - } + "description": "Custom headers to include in the requests." } } }, - "void.ollama": { + "void.ollama.model": { + "type": "string", + "description": "Ollama model. 'codegemma' | 'codegemma:2b' | 'codegemma:7b' | 'codellama' | 'codellama:7b' | 'codellama:13b' | 'codellama:34b' | 'codellama:70b' | 'codellama:code' | 'codellama:python' | 'command-r' | 'command-r:35b' | 'command-r-plus' | 'command-r-plus:104b' | 'deepseek-coder-v2' | 'deepseek-coder-v2:16b' | 'deepseek-coder-v2:236b' | 'falcon2' | 'falcon2:11b' | 'firefunction-v2' | 'firefunction-v2:70b' | 'gemma' | 'gemma:2b' | 'gemma:7b' | 'gemma2' | 'gemma2:2b' | 'gemma2:9b' | 'gemma2:27b' | 'llama2' | 'llama2:7b' | 'llama2:13b' | 'llama2:70b' | 'llama3' | 'llama3:8b' | 'llama3:70b' | 'llama3-chatqa' | 'llama3-chatqa:8b' | 'llama3-chatqa:70b' | 'llama3-gradient' | 'llama3-gradient:8b' | 'llama3-gradient:70b' | 'llama3.1' | 'llama3.1:8b' | 'llama3.1:70b' | 'llama3.1:405b' | 'llava' | 'llava:7b' | 'llava:13b' | 'llava:34b' | 'llava-llama3' | 'llava-llama3:8b' | 'llava-phi3' | 'llava-phi3:3.8b' | 'mistral' | 'mistral:7b' | 'mistral-large' | 'mistral-large:123b' | 'mistral-nemo' | 'mistral-nemo:12b' | 'mixtral' | 'mixtral:8x7b' | 'mixtral:8x22b' | 'moondream' | 'moondream:1.8b' | 'openhermes' | 'openhermes:v2.5' | 'phi3' | 'phi3:3.8b' | 'phi3:14b' | 'phi3.5' | 'phi3.5:3.8b' | 'qwen' | 'qwen:7b' | 'qwen:14b' | 'qwen:32b' | 'qwen:72b' | 'qwen:110b' | 'qwen2' | 'qwen2:0.5b' | 'qwen2:1.5b' | 'qwen2:7b' | 'qwen2:72b' | 'smollm' | 'smollm:135m' | 'smollm:360m' | 'smollm:1.7b'", + "default": "llama3.1", + "enum": [ + "codegemma", + "codegemma:2b", + "codegemma:7b", + "codellama", + "codellama:7b", + "codellama:13b", + "codellama:34b", + "codellama:70b", + "codellama:code", + "codellama:python", + "command-r", + "command-r:35b", + "command-r-plus", + "command-r-plus:104b", + "deepseek-coder-v2", + "deepseek-coder-v2:16b", + "deepseek-coder-v2:236b", + "falcon2", + "falcon2:11b", + "firefunction-v2", + "firefunction-v2:70b", + "gemma", + "gemma:2b", + "gemma:7b", + "gemma2", + "gemma2:2b", + "gemma2:9b", + "gemma2:27b", + "llama2", + "llama2:7b", + "llama2:13b", + "llama2:70b", + "llama3", + "llama3:8b", + "llama3:70b", + "llama3-chatqa", + "llama3-chatqa:8b", + "llama3-chatqa:70b", + "llama3-gradient", + "llama3-gradient:8b", + "llama3-gradient:70b", + "llama3.1", + "llama3.1:8b", + "llama3.1:70b", + "llama3.1:405b", + "llava", + "llava:7b", + "llava:13b", + "llava:34b", + "llava-llama3", + "llava-llama3:8b", + "llava-phi3", + "llava-phi3:3.8b", + "mistral", + "mistral:7b", + "mistral-large", + "mistral-large:123b", + "mistral-nemo", + "mistral-nemo:12b", + "mixtral", + "mixtral:8x7b", + "mixtral:8x22b", + "moondream", + "moondream:1.8b", + "openhermes", + "openhermes:v2.5", + "phi3", + "phi3:3.8b", + "phi3:14b", + "phi3.5", + "phi3.5:3.8b", + "qwen", + "qwen:7b", + "qwen:14b", + "qwen:32b", + "qwen:72b", + "qwen:110b", + "qwen2", + "qwen2:0.5b", + "qwen2:1.5b", + "qwen2:7b", + "qwen2:72b", + "smollm", + "smollm:135m", + "smollm:360m", + "smollm:1.7b" + ] + }, + "void.ollama.providerSettings": { "type": "object", "properties": { - "model": { + "baseURL": { "type": "string", - "description": "Ollama model. 'codegemma' | 'codegemma:2b' | 'codegemma:7b' | 'codellama' | 'codellama:7b' | 'codellama:13b' | 'codellama:34b' | 'codellama:70b' | 'codellama:code' | 'codellama:python' | 'command-r' | 'command-r:35b' | 'command-r-plus' | 'command-r-plus:104b' | 'deepseek-coder-v2' | 'deepseek-coder-v2:16b' | 'deepseek-coder-v2:236b' | 'falcon2' | 'falcon2:11b' | 'firefunction-v2' | 'firefunction-v2:70b' | 'gemma' | 'gemma:2b' | 'gemma:7b' | 'gemma2' | 'gemma2:2b' | 'gemma2:9b' | 'gemma2:27b' | 'llama2' | 'llama2:7b' | 'llama2:13b' | 'llama2:70b' | 'llama3' | 'llama3:8b' | 'llama3:70b' | 'llama3-chatqa' | 'llama3-chatqa:8b' | 'llama3-chatqa:70b' | 'llama3-gradient' | 'llama3-gradient:8b' | 'llama3-gradient:70b' | 'llama3.1' | 'llama3.1:8b' | 'llama3.1:70b' | 'llama3.1:405b' | 'llava' | 'llava:7b' | 'llava:13b' | 'llava:34b' | 'llava-llama3' | 'llava-llama3:8b' | 'llava-phi3' | 'llava-phi3:3.8b' | 'mistral' | 'mistral:7b' | 'mistral-large' | 'mistral-large:123b' | 'mistral-nemo' | 'mistral-nemo:12b' | 'mixtral' | 'mixtral:8x7b' | 'mixtral:8x22b' | 'moondream' | 'moondream:1.8b' | 'openhermes' | 'openhermes:v2.5' | 'phi3' | 'phi3:3.8b' | 'phi3:14b' | 'phi3.5' | 'phi3.5:3.8b' | 'qwen' | 'qwen:7b' | 'qwen:14b' | 'qwen:32b' | 'qwen:72b' | 'qwen:110b' | 'qwen2' | 'qwen2:0.5b' | 'qwen2:1.5b' | 'qwen2:7b' | 'qwen2:72b' | 'smollm' | 'smollm:135m' | 'smollm:360m' | 'smollm:1.7b'", - "default": "llama3.1", - "enum": [ - "codegemma", - "codegemma:2b", - "codegemma:7b", - "codellama", - "codellama:7b", - "codellama:13b", - "codellama:34b", - "codellama:70b", - "codellama:code", - "codellama:python", - "command-r", - "command-r:35b", - "command-r-plus", - "command-r-plus:104b", - "deepseek-coder-v2", - "deepseek-coder-v2:16b", - "deepseek-coder-v2:236b", - "falcon2", - "falcon2:11b", - "firefunction-v2", - "firefunction-v2:70b", - "gemma", - "gemma:2b", - "gemma:7b", - "gemma2", - "gemma2:2b", - "gemma2:9b", - "gemma2:27b", - "llama2", - "llama2:7b", - "llama2:13b", - "llama2:70b", - "llama3", - "llama3:8b", - "llama3:70b", - "llama3-chatqa", - "llama3-chatqa:8b", - "llama3-chatqa:70b", - "llama3-gradient", - "llama3-gradient:8b", - "llama3-gradient:70b", - "llama3.1", - "llama3.1:8b", - "llama3.1:70b", - "llama3.1:405b", - "llava", - "llava:7b", - "llava:13b", - "llava:34b", - "llava-llama3", - "llava-llama3:8b", - "llava-phi3", - "llava-phi3:3.8b", - "mistral", - "mistral:7b", - "mistral-large", - "mistral-large:123b", - "mistral-nemo", - "mistral-nemo:12b", - "mixtral", - "mixtral:8x7b", - "mixtral:8x22b", - "moondream", - "moondream:1.8b", - "openhermes", - "openhermes:v2.5", - "phi3", - "phi3:3.8b", - "phi3:14b", - "phi3.5", - "phi3.5:3.8b", - "qwen", - "qwen:7b", - "qwen:14b", - "qwen:32b", - "qwen:72b", - "qwen:110b", - "qwen2", - "qwen2:0.5b", - "qwen2:1.5b", - "qwen2:7b", - "qwen2:72b", - "smollm", - "smollm:135m", - "smollm:360m", - "smollm:1.7b" - ] + "description": "Ollama base URL. Local API server can be started with `OLLAMA_ORIGINS=* ollama serve`" }, - "providerSettings": { + "headers": { "type": "object", - "properties": { - "baseURL": { - "type": "string", - "description": "Ollama base URL. Local API server can be started with `OLLAMA_ORIGINS=* ollama serve`" - }, - "headers": { - "type": "object", - "description": "Custom headers to include in the requests." - } - } + "description": "Custom headers to include in the requests." } } }, + "void.greptile.apiKey": { + "type": "string", + "description": "Greptile API key." + }, "void.greptile": { "type": "object", "properties": { "providerSettings": { "type": "object", "properties": { - "apikey": { - "type": "string", - "description": "Greptile API key." - }, "headers": { "type": "object", "description": "Custom headers to include in the requests.", diff --git a/extensions/void/src/SidebarWebviewProvider.ts b/extensions/void/src/SidebarWebviewProvider.ts index c95e1e12..c1533cca 100644 --- a/extensions/void/src/SidebarWebviewProvider.ts +++ b/extensions/void/src/SidebarWebviewProvider.ts @@ -57,11 +57,11 @@ export class SidebarWebviewProvider implements vscode.WebviewViewProvider { const ollamaBaseURL = new URL('/', vscode.workspace.getConfiguration('void').get('ollama.providerSettings.baseURL') || 'http://127.0.0.1:11434').toString() - const azureProviderSettings = vscode.workspace.getConfiguration('void').get('azure.providerSettings') as AzureOpenAIProviderSettings - const azureBaseURL = new URL('/', vscode.workspace.getConfiguration('void').get('azure.providerSettings.baseURL') || `https://${azureProviderSettings.resourceName}.openai.azure.com/openai/deployments`).toString() + const azureResourceName = vscode.workspace.getConfiguration('void').get('azure.resourceName') ?? '' + const azureBaseURL = new URL('/', vscode.workspace.getConfiguration('void').get('azure.providerSettings.baseURL') || `https://${azureResourceName}.openai.azure.com/openai/deployments`).toString() const openaiBaseURL = new URL('/', vscode.workspace.getConfiguration('void').get('openai.providerSettings.baseURL') || 'https://api.openai.com').toString() - const greptileBaseURL = new URL('/', vscode.workspace.getConfiguration('void').get('greptile.providerSettings.baseURL') || 'https://api.mistral.ai').toString() - const anthropicBaseURL = new URL('/', vscode.workspace.getConfiguration('void').get('anthropic.providerSettings.baseURL') || 'https://api.mistral.ai').toString() + const greptileBaseURL = new URL('/', vscode.workspace.getConfiguration('void').get('greptile.providerSettings.baseURL') || 'https://api.greptile.com').toString() + const anthropicBaseURL = new URL('/', vscode.workspace.getConfiguration('void').get('anthropic.providerSettings.baseURL') || 'https://api.anthropic.com').toString() const allowed_urls = [ ollamaBaseURL, azureBaseURL, diff --git a/extensions/void/src/common/sendLLMMessage.ts b/extensions/void/src/common/sendLLMMessage.ts index 256f2ca2..479a61d3 100644 --- a/extensions/void/src/common/sendLLMMessage.ts +++ b/extensions/void/src/common/sendLLMMessage.ts @@ -10,21 +10,24 @@ export type ApiConfig = { anthropic: { /** @default 'claude-3-5-sonnet-20240620' */ model: string, - providerSettings?: AnthropicProviderSettings + apiKey: string, + providerSettings?: Omit }, openai: { /** @default 'gpt-4o' */ model: string, - providerSettings?: OpenAIProviderSettings + apiKey: string, + providerSettings?: Omit }, azure: { deploymentId: string, - providerSettings?: AzureOpenAIProviderSettings + resourceName: string, + apiKey: string, + providerSettings?: Omit }, greptile: { + apiKey: string, providerSettings?: { - apikey?: string, - githubPAT?: string, headers?: Record, repoinfo?: { remote?: string, // e.g. 'github' @@ -83,7 +86,7 @@ const sendGreptileMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFin fetch('https://api.greptile.com/v2/query', { method: 'POST', headers: { - "Authorization": `Bearer ${apiConfig.greptile.providerSettings?.apikey}`, + "Authorization": `Bearer ${apiConfig.greptile.apiKey}`, "Content-Type": `application/json`, ...apiConfig.greptile.providerSettings?.headers }, @@ -164,10 +167,20 @@ export const sendLLMMessage: SendLLMMessageFnTypeExternal = ({ messages, onText, export const getAiModel = (apiConfig: ApiConfig) => { switch (apiConfig.provider) { - case 'openai': return createOpenAI(apiConfig.openai.providerSettings)(apiConfig.openai.model || 'gpt-4o') - case 'anthropic': return createAnthropic(apiConfig.anthropic.providerSettings)(apiConfig.anthropic.model || 'claude-3-5-sonnet-20240620') + case 'openai': return createOpenAI({ + ...apiConfig.openai.providerSettings, + apiKey: apiConfig.openai.apiKey, + })(apiConfig.openai.model || 'gpt-4o') + case 'anthropic': return createAnthropic({ + ...apiConfig.anthropic.providerSettings, + apiKey: apiConfig.anthropic.apiKey, + })(apiConfig.anthropic.model || 'claude-3-5-sonnet-20240620') case 'ollama': return createOllama(apiConfig.ollama.providerSettings)(apiConfig.ollama.model || 'llama3.1') - case 'azure': return createAzure(apiConfig.azure.providerSettings)(`${apiConfig.azure.deploymentId}`) + case 'azure': return createAzure({ + ...apiConfig.azure.providerSettings, + apiKey: apiConfig.azure.apiKey, + resourceName: apiConfig.azure.resourceName, + })(`${apiConfig.azure.deploymentId}`) default: throw new Error(`Error: provider was ${apiConfig.provider}, which is not recognized!`) } diff --git a/extensions/void/src/extension.ts b/extensions/void/src/extension.ts index 0b218bcd..5d2ae6c0 100644 --- a/extensions/void/src/extension.ts +++ b/extensions/void/src/extension.ts @@ -15,18 +15,22 @@ const getApiConfig = () => { provider: vscode.workspace.getConfiguration('void').get('provider') ?? 'anthropic', anthropic: { model: vscode.workspace.getConfiguration('void').get('anthropic.model') ?? 'claude-3-5-sonnet-20240620', + apiKey: vscode.workspace.getConfiguration('void').get('anthropic.apiKey') ?? '', providerSettings: { ...vscode.workspace.getConfiguration('void').get('anthropic.providerSettings') ?? {}, }, }, openai: { model: vscode.workspace.getConfiguration('void').get('openai.model') ?? 'gpt-4o', + apiKey: vscode.workspace.getConfiguration('void').get('openai.apiKey') ?? '', providerSettings: { ...vscode.workspace.getConfiguration('void').get('openai.providerSettings') ?? {}, }, }, azure: { deploymentId: vscode.workspace.getConfiguration('void').get('azure.deploymentId') ?? '', + resourceName: vscode.workspace.getConfiguration('void').get('azure.resourceName') ?? '', + apiKey: vscode.workspace.getConfiguration('void').get('azure.apiKey') ?? '', providerSettings: { ...vscode.workspace.getConfiguration('void').get('azure.providerSettings') ?? {}, }, @@ -38,11 +42,13 @@ const getApiConfig = () => { }, }, greptile: { + apiKey: vscode.workspace.getConfiguration('void').get('greptile.apiKey') ?? '', providerSettings: { ...vscode.workspace.getConfiguration('void').get('greptile.providerSettings') ?? {}, } }, } + return apiConfig }