From 4da35b9cf5069c0594ea535c43f6c2476d3a0abe Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 22 Oct 2024 16:45:26 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20feat:=20Add=20support=20for=20`c?= =?UTF-8?q?laude-3-5-sonnet-20241022`=20=20(#4510)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 2 +- api/app/clients/AnthropicClient.js | 3 ++ api/app/clients/specs/AnthropicClient.test.js | 30 +++++++++++++++++-- api/utils/tokens.js | 2 ++ packages/data-provider/src/config.ts | 2 ++ packages/data-provider/src/schemas.ts | 2 +- 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 3e4f4e8845..dd99dce756 100644 --- a/.env.example +++ b/.env.example @@ -82,7 +82,7 @@ PROXY= #============# ANTHROPIC_API_KEY=user_provided -# ANTHROPIC_MODELS=claude-3-5-sonnet-20240620,claude-3-opus-20240229,claude-3-sonnet-20240229,claude-3-haiku-20240307,claude-2.1,claude-2,claude-1.2,claude-1,claude-1-100k,claude-instant-1,claude-instant-1-100k +# ANTHROPIC_MODELS=claude-3-5-sonnet-20241022,claude-3-5-sonnet-latest,claude-3-5-sonnet-20240620,claude-3-opus-20240229,claude-3-sonnet-20240229,claude-3-haiku-20240307,claude-2.1,claude-2,claude-1.2,claude-1,claude-1-100k,claude-instant-1,claude-instant-1-100k # ANTHROPIC_REVERSE_PROXY= #============# diff --git a/api/app/clients/AnthropicClient.js b/api/app/clients/AnthropicClient.js index 486af95c3f..ff0dc4de5b 100644 --- a/api/app/clients/AnthropicClient.js +++ b/api/app/clients/AnthropicClient.js @@ -682,6 +682,9 @@ class AnthropicClient extends BaseClient { */ checkPromptCacheSupport(modelName) { const modelMatch = matchModelName(modelName, EModelEndpoint.anthropic); + if (modelMatch.includes('claude-3-5-sonnet-latest')) { + return false; + } if ( modelMatch === 'claude-3-5-sonnet' || modelMatch === 'claude-3-haiku' || diff --git a/api/app/clients/specs/AnthropicClient.test.js b/api/app/clients/specs/AnthropicClient.test.js index 29267de462..eef6bb6748 100644 --- a/api/app/clients/specs/AnthropicClient.test.js +++ b/api/app/clients/specs/AnthropicClient.test.js @@ -201,10 +201,10 @@ describe('AnthropicClient', () => { ); }); - it('should add beta header for claude-3-5-sonnet model', () => { + it('should add "max-tokens" & "prompt-caching" beta header for claude-3-5-sonnet model', () => { const client = new AnthropicClient('test-api-key'); const modelOptions = { - model: 'claude-3-5-sonnet-20240307', + model: 'claude-3-5-sonnet-20241022', }; client.setOptions({ modelOptions, promptCache: true }); const anthropicClient = client.getClient(modelOptions); @@ -215,7 +215,7 @@ describe('AnthropicClient', () => { ); }); - it('should add beta header for claude-3-haiku model', () => { + it('should add "prompt-caching" beta header for claude-3-haiku model', () => { const client = new AnthropicClient('test-api-key'); const modelOptions = { model: 'claude-3-haiku-2028', @@ -229,6 +229,30 @@ describe('AnthropicClient', () => { ); }); + it('should add "prompt-caching" beta header for claude-3-opus model', () => { + const client = new AnthropicClient('test-api-key'); + const modelOptions = { + model: 'claude-3-opus-2028', + }; + client.setOptions({ modelOptions, promptCache: true }); + const anthropicClient = client.getClient(modelOptions); + expect(anthropicClient._options.defaultHeaders).toBeDefined(); + expect(anthropicClient._options.defaultHeaders).toHaveProperty('anthropic-beta'); + expect(anthropicClient._options.defaultHeaders['anthropic-beta']).toBe( + 'prompt-caching-2024-07-31', + ); + }); + + it('should not add beta header for claude-3-5-sonnet-latest model', () => { + const client = new AnthropicClient('test-api-key'); + const modelOptions = { + model: 'anthropic/claude-3-5-sonnet-latest', + }; + client.setOptions({ modelOptions, promptCache: true }); + const anthropicClient = client.getClient(modelOptions); + expect(anthropicClient.defaultHeaders).not.toHaveProperty('anthropic-beta'); + }); + it('should not add beta header for other models', () => { const client = new AnthropicClient('test-api-key'); client.setOptions({ diff --git a/api/utils/tokens.js b/api/utils/tokens.js index 6e5a131611..362b2fc670 100644 --- a/api/utils/tokens.js +++ b/api/utils/tokens.js @@ -72,6 +72,8 @@ const anthropicModels = { 'claude-3-opus': 200000, 'claude-3-5-sonnet': 200000, 'claude-3.5-sonnet': 200000, + 'claude-3-5-sonnet-latest': 200000, + 'claude-3.5-sonnet-latest': 200000, }; const metaModels = { diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index 6ff6a46926..b57f50c16e 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -607,7 +607,9 @@ const sharedOpenAIModels = [ ]; const sharedAnthropicModels = [ + 'claude-3-5-sonnet-20241022', 'claude-3-5-sonnet-20240620', + 'claude-3-5-sonnet-latest', 'claude-3-opus-20240229', 'claude-3-sonnet-20240229', 'claude-3-haiku-20240307', diff --git a/packages/data-provider/src/schemas.ts b/packages/data-provider/src/schemas.ts index 3cca428e83..81fdf28a74 100644 --- a/packages/data-provider/src/schemas.ts +++ b/packages/data-provider/src/schemas.ts @@ -241,7 +241,7 @@ const ANTHROPIC_MAX_OUTPUT = 8192; const LEGACY_ANTHROPIC_MAX_OUTPUT = 4096; export const anthropicSettings = { model: { - default: 'claude-3-5-sonnet-20240620', + default: 'claude-3-5-sonnet-20241022', }, temperature: { min: 0,