From 1843cd0878899c37dfd4401c751691a59f36c547 Mon Sep 17 00:00:00 2001 From: Dave Hogan Date: Sat, 21 Sep 2024 01:57:34 +0100 Subject: [PATCH] Makes anthropic model and max_tokens configurable Makes whichApi an enum for less error prone configuration --- extensions/void/package.json | 14 +++++++++++++- extensions/void/src/common/sendLLMMessage.ts | 6 ++++-- extensions/void/src/extension.ts | 8 ++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/extensions/void/package.json b/extensions/void/package.json index ebccfe72..94aff351 100644 --- a/extensions/void/package.json +++ b/extensions/void/package.json @@ -18,13 +18,25 @@ "void.whichApi": { "type": "string", "default": "anthropic", - "description": "Choose a model to use (anthropic | openai | greptile | ollama)" + "description": "Choose an API provider", + "enum": ["anthropic", "openai", "greptile", "ollama"] }, "void.anthropicApiKey": { "type": "string", "default": "", "description": "Anthropic API Key" }, + "void.anthropicModel":{ + "type": "string", + "default": "claude-3-5-sonnet-20240620", + "description": "Anthropic Model to use", + "enum": ["claude-3-5-sonnet-20240620"] + }, + "void.anthropicMaxTokens":{ + "type": "number", + "default": 1024, + "description": "Max Token to use when using Anthropic API" + }, "void.openAIApiKey": { "type": "string", "default": "", diff --git a/extensions/void/src/common/sendLLMMessage.ts b/extensions/void/src/common/sendLLMMessage.ts index ca3c34bd..40b8e945 100644 --- a/extensions/void/src/common/sendLLMMessage.ts +++ b/extensions/void/src/common/sendLLMMessage.ts @@ -6,6 +6,8 @@ import OpenAI from 'openai'; export type ApiConfig = { anthropic: { apikey: string, + model: string, + maxTokens: number }, openai: { apikey: string @@ -64,8 +66,8 @@ const sendClaudeMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinal const anthropic = new Anthropic({ apiKey: apiConfig.anthropic.apikey, dangerouslyAllowBrowser: true }); // defaults to process.env["ANTHROPIC_API_KEY"] const stream = anthropic.messages.stream({ - model: "claude-3-5-sonnet-20240620", - max_tokens: 1024, + model: apiConfig.anthropic.model, + max_tokens: apiConfig.anthropic.maxTokens, messages: messages, }); diff --git a/extensions/void/src/extension.ts b/extensions/void/src/extension.ts index 4cd8ac26..1ddb26ae 100644 --- a/extensions/void/src/extension.ts +++ b/extensions/void/src/extension.ts @@ -13,7 +13,11 @@ const readFileContentOfUri = async (uri: vscode.Uri) => { const getApiConfig = () => { const apiConfig: ApiConfig = { - anthropic: { apikey: vscode.workspace.getConfiguration('void').get('anthropicApiKey') ?? '' }, + anthropic: { + apikey: vscode.workspace.getConfiguration('void').get('anthropicApiKey') ?? '', + model: vscode.workspace.getConfiguration('void').get('anthropicModel') ?? '', + maxTokens: vscode.workspace.getConfiguration('void').get('anthropicMaxToken') ?? 1024, + }, openai: { apikey: vscode.workspace.getConfiguration('void').get('openAIApiKey') ?? '' }, greptile: { apikey: vscode.workspace.getConfiguration('void').get('greptileApiKey') ?? '', @@ -27,7 +31,7 @@ const getApiConfig = () => { ollama: { // apikey: vscode.workspace.getConfiguration('void').get('ollamaSettings') ?? '', }, - whichApi: vscode.workspace.getConfiguration('void').get('whichApi') ?? '' + whichApi: vscode.workspace.getConfiguration('void').get('whichApi') ?? 'anthropic' } return apiConfig }