Skip to content

Commit 494947b

Browse files
authored
added support for latest sonnet 3.5 and haiku 3.5 and updated tests (#184)
1 parent 9cfd25f commit 494947b

File tree

2 files changed

+70
-15
lines changed

2 files changed

+70
-15
lines changed

plugins/anthropic/src/claude.test.ts

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import type { CandidateData, ToolDefinition } from 'genkit/model';
4141

4242
import type { AnthropicConfigSchema } from './claude';
4343
import {
44-
claude3Haiku,
44+
claude35Haiku,
4545
claudeModel,
4646
claudeRunner,
4747
fromAnthropicContentBlockChunk,
@@ -678,7 +678,40 @@ describe('toAnthropicRequestBody', () => {
678678
role: 'user',
679679
},
680680
],
681-
model: 'claude-3-5-sonnet-20240620',
681+
model: 'claude-3-5-sonnet-latest',
682+
metadata: {
683+
user_id: 'exampleUser123',
684+
},
685+
},
686+
},
687+
{
688+
should: '(claude-3-5-haiku) handles request with text messages',
689+
modelName: 'claude-3-5-haiku',
690+
genkitRequest: {
691+
messages: [
692+
{ role: 'user', content: [{ text: 'Tell a joke about dogs.' }] },
693+
],
694+
output: { format: 'text' },
695+
config: {
696+
metadata: {
697+
user_id: 'exampleUser123',
698+
},
699+
},
700+
},
701+
expectedOutput: {
702+
max_tokens: 4096,
703+
messages: [
704+
{
705+
content: [
706+
{
707+
text: 'Tell a joke about dogs.',
708+
type: 'text',
709+
},
710+
],
711+
role: 'user',
712+
},
713+
],
714+
model: 'claude-3-5-haiku-latest',
682715
metadata: {
683716
user_id: 'exampleUser123',
684717
},
@@ -804,7 +837,7 @@ describe('toAnthropicRequestBody', () => {
804837

805838
it('should throw if output format is not text', () => {
806839
expect(() =>
807-
toAnthropicRequestBody('claude-3-haiku', {
840+
toAnthropicRequestBody('claude-3-5-haiku', {
808841
messages: [],
809842
tools: [],
810843
output: { format: 'media' },
@@ -825,7 +858,7 @@ describe('toAnthropicRequestBody', () => {
825858

826859
// Test with caching enabled
827860
const outputWithCaching = toAnthropicRequestBody(
828-
'claude-3-haiku',
861+
'claude-3-5-haiku',
829862
request,
830863
false,
831864
true
@@ -840,7 +873,7 @@ describe('toAnthropicRequestBody', () => {
840873

841874
// Test with caching disabled
842875
const outputWithoutCaching = toAnthropicRequestBody(
843-
'claude-3-haiku',
876+
'claude-3-5-haiku',
844877
request,
845878
false,
846879
false
@@ -863,12 +896,12 @@ describe('claudeRunner', () => {
863896
},
864897
};
865898
const runner = claudeRunner(
866-
'claude-3-haiku',
899+
'claude-3-5-haiku',
867900
anthropicClient as unknown as Anthropic
868901
);
869902
await runner({ messages: [] });
870903
expect(anthropicClient.messages.create).toHaveBeenCalledWith({
871-
model: 'claude-3-haiku-20240307',
904+
model: 'claude-3-5-haiku-latest',
872905
max_tokens: 4096,
873906
});
874907
});
@@ -916,12 +949,12 @@ describe('claudeRunner', () => {
916949
};
917950
const streamingCallback = jest.fn();
918951
const runner = claudeRunner(
919-
'claude-3-haiku',
952+
'claude-3-5-haiku',
920953
anthropicClient as unknown as Anthropic
921954
);
922955
await runner({ messages: [] }, streamingCallback);
923956
expect(anthropicClient.messages.stream).toHaveBeenCalledWith({
924-
model: 'claude-3-haiku-20240307',
957+
model: 'claude-3-5-haiku-latest',
925958
max_tokens: 4096,
926959
stream: true,
927960
});
@@ -943,12 +976,12 @@ describe('claudeModel', () => {
943976

944977
it('should correctly define supported Claude models', () => {
945978
jest.spyOn(ai, 'defineModel').mockImplementation((() => ({})) as any);
946-
claudeModel(ai, 'claude-3-haiku', {} as Anthropic);
979+
claudeModel(ai, 'claude-3-5-haiku', {} as Anthropic);
947980
expect(ai.defineModel).toHaveBeenCalledWith(
948981
{
949-
name: claude3Haiku.name,
950-
...claude3Haiku.info,
951-
configSchema: claude3Haiku.configSchema,
982+
name: claude35Haiku.name,
983+
...claude35Haiku.info,
984+
configSchema: claude35Haiku.configSchema,
952985
},
953986
expect.any(Function)
954987
);

plugins/anthropic/src/claude.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export const AnthropicConfigSchema = GenerationCommonConfigSchema.extend({
7373
export const claude35Sonnet = modelRef({
7474
name: 'anthropic/claude-3-5-sonnet',
7575
info: {
76-
versions: ['claude-3-5-sonnet-20240620'],
76+
versions: [
77+
'claude-3-5-sonnet-20240620',
78+
'claude-3-5-sonnet-20241022',
79+
'claude-3-5-sonnet-latest',
80+
],
7781
label: 'Anthropic - Claude 3.5 Sonnet',
7882
supports: {
7983
multiturn: true,
@@ -84,7 +88,7 @@ export const claude35Sonnet = modelRef({
8488
},
8589
},
8690
configSchema: AnthropicConfigSchema,
87-
version: 'claude-3-5-sonnet-20240620',
91+
version: 'claude-3-5-sonnet-latest',
8892
});
8993

9094
export const claude3Opus = modelRef({
@@ -138,6 +142,23 @@ export const claude3Haiku = modelRef({
138142
version: 'claude-3-haiku-20240307',
139143
});
140144

145+
export const claude35Haiku = modelRef({
146+
name: 'anthropic/claude-3-5-haiku',
147+
info: {
148+
versions: ['claude-3-5-haiku-20241022', 'claude-3-5-haiku-latest'],
149+
label: 'Anthropic - Claude 3.5 Haiku',
150+
supports: {
151+
multiturn: true,
152+
tools: true,
153+
media: true,
154+
systemRole: true,
155+
output: ['text'],
156+
},
157+
},
158+
configSchema: AnthropicConfigSchema,
159+
version: 'claude-3-5-haiku-latest',
160+
});
161+
141162
export const SUPPORTED_CLAUDE_MODELS: Record<
142163
string,
143164
ModelReference<typeof AnthropicConfigSchema>
@@ -146,6 +167,7 @@ export const SUPPORTED_CLAUDE_MODELS: Record<
146167
'claude-3-opus': claude3Opus,
147168
'claude-3-sonnet': claude3Sonnet,
148169
'claude-3-haiku': claude3Haiku,
170+
'claude-3-5-haiku': claude35Haiku,
149171
};
150172

151173
/**

0 commit comments

Comments
 (0)