Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 feat: Claude 3.5 Haiku #4629

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ PROXY=
#============#

ANTHROPIC_API_KEY=user_provided
# 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_MODELS=claude-3-5-haiku-20241022,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=

#============#
Expand Down
7 changes: 4 additions & 3 deletions api/app/clients/AnthropicClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class AnthropicClient extends BaseClient {
);

const modelMatch = matchModelName(this.modelOptions.model, EModelEndpoint.anthropic);
this.isClaude3 = modelMatch.startsWith('claude-3');
this.isLegacyOutput = !modelMatch.startsWith('claude-3-5-sonnet');
this.isClaude3 = modelMatch.includes('claude-3');
this.isLegacyOutput = !modelMatch.includes('claude-3-5-sonnet');
this.supportsCacheControl =
this.options.promptCache && this.checkPromptCacheSupport(modelMatch);

Expand Down Expand Up @@ -634,7 +634,7 @@ class AnthropicClient extends BaseClient {
);
};

if (this.modelOptions.model.startsWith('claude-3')) {
if (this.modelOptions.model.includes('claude-3')) {
await buildMessagesPayload();
processTokens();
return {
Expand Down Expand Up @@ -687,6 +687,7 @@ class AnthropicClient extends BaseClient {
}
if (
modelMatch === 'claude-3-5-sonnet' ||
modelMatch === 'claude-3-5-haiku' ||
modelMatch === 'claude-3-haiku' ||
modelMatch === 'claude-3-opus'
) {
Expand Down
4 changes: 4 additions & 0 deletions api/models/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const tokenValues = Object.assign(
'claude-3-sonnet': { prompt: 3, completion: 15 },
'claude-3-5-sonnet': { prompt: 3, completion: 15 },
'claude-3.5-sonnet': { prompt: 3, completion: 15 },
'claude-3-5-haiku': { prompt: 1, completion: 5 },
'claude-3.5-haiku': { prompt: 1, completion: 5 },
'claude-3-haiku': { prompt: 0.25, completion: 1.25 },
'claude-2.1': { prompt: 8, completion: 24 },
'claude-2': { prompt: 8, completion: 24 },
Expand All @@ -81,6 +83,8 @@ const tokenValues = Object.assign(
const cacheTokenValues = {
'claude-3.5-sonnet': { write: 3.75, read: 0.3 },
'claude-3-5-sonnet': { write: 3.75, read: 0.3 },
'claude-3.5-haiku': { write: 1.25, read: 0.1 },
'claude-3-5-haiku': { write: 1.25, read: 0.1 },
'claude-3-haiku': { write: 0.3, read: 0.03 },
};

Expand Down
16 changes: 16 additions & 0 deletions api/models/tx.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ describe('getValueKey', () => {
expect(getValueKey('claude-3.5-sonnet-turbo')).toBe('claude-3.5-sonnet');
expect(getValueKey('claude-3.5-sonnet-0125')).toBe('claude-3.5-sonnet');
});

it('should return "claude-3-5-haiku" for model type of "claude-3-5-haiku-"', () => {
expect(getValueKey('claude-3-5-haiku-20240620')).toBe('claude-3-5-haiku');
expect(getValueKey('anthropic/claude-3-5-haiku')).toBe('claude-3-5-haiku');
expect(getValueKey('claude-3-5-haiku-turbo')).toBe('claude-3-5-haiku');
expect(getValueKey('claude-3-5-haiku-0125')).toBe('claude-3-5-haiku');
});

it('should return "claude-3.5-haiku" for model type of "claude-3.5-haiku-"', () => {
expect(getValueKey('claude-3.5-haiku-20240620')).toBe('claude-3.5-haiku');
expect(getValueKey('anthropic/claude-3.5-haiku')).toBe('claude-3.5-haiku');
expect(getValueKey('claude-3.5-haiku-turbo')).toBe('claude-3.5-haiku');
expect(getValueKey('claude-3.5-haiku-0125')).toBe('claude-3.5-haiku');
});
});

describe('getMultiplier', () => {
Expand Down Expand Up @@ -248,6 +262,8 @@ describe('getCacheMultiplier', () => {
it('should return the correct cache multiplier for a given valueKey and cacheType', () => {
expect(getCacheMultiplier({ valueKey: 'claude-3-5-sonnet', cacheType: 'write' })).toBe(3.75);
expect(getCacheMultiplier({ valueKey: 'claude-3-5-sonnet', cacheType: 'read' })).toBe(0.3);
expect(getCacheMultiplier({ valueKey: 'claude-3-5-haiku', cacheType: 'write' })).toBe(1.25);
expect(getCacheMultiplier({ valueKey: 'claude-3-5-haiku', cacheType: 'read' })).toBe(0.1);
expect(getCacheMultiplier({ valueKey: 'claude-3-haiku', cacheType: 'write' })).toBe(0.3);
expect(getCacheMultiplier({ valueKey: 'claude-3-haiku', cacheType: 'read' })).toBe(0.03);
});
Expand Down
2 changes: 2 additions & 0 deletions api/utils/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const anthropicModels = {
'claude-3-haiku': 200000,
'claude-3-sonnet': 200000,
'claude-3-opus': 200000,
'claude-3.5-haiku': 200000,
'claude-3-5-haiku': 200000,
'claude-3-5-sonnet': 200000,
'claude-3.5-sonnet': 200000,
'claude-3-5-sonnet-latest': 200000,
Expand Down
1 change: 1 addition & 0 deletions packages/data-provider/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ const sharedOpenAIModels = [
];

const sharedAnthropicModels = [
'claude-3-5-haiku-20241022',
'claude-3-5-sonnet-20241022',
'claude-3-5-sonnet-20240620',
'claude-3-5-sonnet-latest',
Expand Down
Loading