From 1843cd0878899c37dfd4401c751691a59f36c547 Mon Sep 17 00:00:00 2001 From: Dave Hogan Date: Sat, 21 Sep 2024 01:57:34 +0100 Subject: [PATCH 1/4] 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 } From 2661f5e8e13c55e6f5231db01fb5588028a97057 Mon Sep 17 00:00:00 2001 From: Dave Hogan Date: Sun, 22 Sep 2024 17:32:33 +0100 Subject: [PATCH 2/4] Implemented feedback, removing explict defaults as this comes from package.json --- extensions/void/src/common/sendLLMMessage.ts | 5 ++--- extensions/void/src/extension.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/extensions/void/src/common/sendLLMMessage.ts b/extensions/void/src/common/sendLLMMessage.ts index 40b8e945..9e47a80a 100644 --- a/extensions/void/src/common/sendLLMMessage.ts +++ b/extensions/void/src/common/sendLLMMessage.ts @@ -7,7 +7,7 @@ export type ApiConfig = { anthropic: { apikey: string, model: string, - maxTokens: number + maxTokens: string }, openai: { apikey: string @@ -62,12 +62,11 @@ type SendLLMMessageFnTypeExternal = (params: { // Claude const sendClaudeMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinalMessage, apiConfig }) => { - const anthropic = new Anthropic({ apiKey: apiConfig.anthropic.apikey, dangerouslyAllowBrowser: true }); // defaults to process.env["ANTHROPIC_API_KEY"] const stream = anthropic.messages.stream({ model: apiConfig.anthropic.model, - max_tokens: apiConfig.anthropic.maxTokens, + max_tokens: parseInt(apiConfig.anthropic.maxTokens), messages: messages, }); diff --git a/extensions/void/src/extension.ts b/extensions/void/src/extension.ts index 1ddb26ae..6df69c77 100644 --- a/extensions/void/src/extension.ts +++ b/extensions/void/src/extension.ts @@ -16,7 +16,7 @@ const getApiConfig = () => { anthropic: { apikey: vscode.workspace.getConfiguration('void').get('anthropicApiKey') ?? '', model: vscode.workspace.getConfiguration('void').get('anthropicModel') ?? '', - maxTokens: vscode.workspace.getConfiguration('void').get('anthropicMaxToken') ?? 1024, + maxTokens: vscode.workspace.getConfiguration('void').get('anthropicMaxToken') ?? '', }, openai: { apikey: vscode.workspace.getConfiguration('void').get('openAIApiKey') ?? '' }, greptile: { From cbe3d4bd4507f852055bdb1031f31660933701d5 Mon Sep 17 00:00:00 2001 From: Dave Hogan Date: Sun, 22 Sep 2024 17:36:53 +0100 Subject: [PATCH 3/4] Removes unnessary default --- extensions/void/src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/void/src/extension.ts b/extensions/void/src/extension.ts index 6df69c77..250af285 100644 --- a/extensions/void/src/extension.ts +++ b/extensions/void/src/extension.ts @@ -31,7 +31,7 @@ const getApiConfig = () => { ollama: { // apikey: vscode.workspace.getConfiguration('void').get('ollamaSettings') ?? '', }, - whichApi: vscode.workspace.getConfiguration('void').get('whichApi') ?? 'anthropic' + whichApi: vscode.workspace.getConfiguration('void').get('whichApi') ?? '' } return apiConfig } From 4747691e7422f3a926cfdf88f0cc3e8b23cd75d3 Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Mon, 30 Sep 2024 00:53:07 -0700 Subject: [PATCH 4/4] add enum --- extensions/void/package.json | 18 ++++++++++-------- void | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) create mode 160000 void diff --git a/extensions/void/package.json b/extensions/void/package.json index 5cf913f0..28b7d4e7 100644 --- a/extensions/void/package.json +++ b/extensions/void/package.json @@ -19,23 +19,25 @@ "type": "string", "default": "anthropic", "description": "Choose an API provider", - "enum": ["anthropic", "openai", "greptile", "ollama"] + "enum": [ + "anthropic", + "openai", + "greptile", + "ollama" + ] }, "void.anthropicApiKey": { "type": "string", "default": "", "description": "Anthropic API Key" }, - "void.anthropicModel":{ + "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" + "enum": [ + "claude-3-5-sonnet-20240620" + ] }, "void.openAIApiKey": { "type": "string", diff --git a/void b/void new file mode 160000 index 00000000..6d513a1e --- /dev/null +++ b/void @@ -0,0 +1 @@ +Subproject commit 6d513a1e602c8dea3f89f85cc5a04d840a0abfa9