Skip to content

Commit

Permalink
added support for latest sonnet 3.5 and haiku 3.5 and updated tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danwritecode authored Dec 1, 2024
1 parent 9cfd25f commit 494947b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 15 deletions.
59 changes: 46 additions & 13 deletions plugins/anthropic/src/claude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import type { CandidateData, ToolDefinition } from 'genkit/model';

import type { AnthropicConfigSchema } from './claude';
import {
claude3Haiku,
claude35Haiku,
claudeModel,
claudeRunner,
fromAnthropicContentBlockChunk,
Expand Down Expand Up @@ -678,7 +678,40 @@ describe('toAnthropicRequestBody', () => {
role: 'user',
},
],
model: 'claude-3-5-sonnet-20240620',
model: 'claude-3-5-sonnet-latest',
metadata: {
user_id: 'exampleUser123',
},
},
},
{
should: '(claude-3-5-haiku) handles request with text messages',
modelName: 'claude-3-5-haiku',
genkitRequest: {
messages: [
{ role: 'user', content: [{ text: 'Tell a joke about dogs.' }] },
],
output: { format: 'text' },
config: {
metadata: {
user_id: 'exampleUser123',
},
},
},
expectedOutput: {
max_tokens: 4096,
messages: [
{
content: [
{
text: 'Tell a joke about dogs.',
type: 'text',
},
],
role: 'user',
},
],
model: 'claude-3-5-haiku-latest',
metadata: {
user_id: 'exampleUser123',
},
Expand Down Expand Up @@ -804,7 +837,7 @@ describe('toAnthropicRequestBody', () => {

it('should throw if output format is not text', () => {
expect(() =>
toAnthropicRequestBody('claude-3-haiku', {
toAnthropicRequestBody('claude-3-5-haiku', {
messages: [],
tools: [],
output: { format: 'media' },
Expand All @@ -825,7 +858,7 @@ describe('toAnthropicRequestBody', () => {

// Test with caching enabled
const outputWithCaching = toAnthropicRequestBody(
'claude-3-haiku',
'claude-3-5-haiku',
request,
false,
true
Expand All @@ -840,7 +873,7 @@ describe('toAnthropicRequestBody', () => {

// Test with caching disabled
const outputWithoutCaching = toAnthropicRequestBody(
'claude-3-haiku',
'claude-3-5-haiku',
request,
false,
false
Expand All @@ -863,12 +896,12 @@ describe('claudeRunner', () => {
},
};
const runner = claudeRunner(
'claude-3-haiku',
'claude-3-5-haiku',
anthropicClient as unknown as Anthropic
);
await runner({ messages: [] });
expect(anthropicClient.messages.create).toHaveBeenCalledWith({
model: 'claude-3-haiku-20240307',
model: 'claude-3-5-haiku-latest',
max_tokens: 4096,
});
});
Expand Down Expand Up @@ -916,12 +949,12 @@ describe('claudeRunner', () => {
};
const streamingCallback = jest.fn();
const runner = claudeRunner(
'claude-3-haiku',
'claude-3-5-haiku',
anthropicClient as unknown as Anthropic
);
await runner({ messages: [] }, streamingCallback);
expect(anthropicClient.messages.stream).toHaveBeenCalledWith({
model: 'claude-3-haiku-20240307',
model: 'claude-3-5-haiku-latest',
max_tokens: 4096,
stream: true,
});
Expand All @@ -943,12 +976,12 @@ describe('claudeModel', () => {

it('should correctly define supported Claude models', () => {
jest.spyOn(ai, 'defineModel').mockImplementation((() => ({})) as any);
claudeModel(ai, 'claude-3-haiku', {} as Anthropic);
claudeModel(ai, 'claude-3-5-haiku', {} as Anthropic);
expect(ai.defineModel).toHaveBeenCalledWith(
{
name: claude3Haiku.name,
...claude3Haiku.info,
configSchema: claude3Haiku.configSchema,
name: claude35Haiku.name,
...claude35Haiku.info,
configSchema: claude35Haiku.configSchema,
},
expect.any(Function)
);
Expand Down
26 changes: 24 additions & 2 deletions plugins/anthropic/src/claude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export const AnthropicConfigSchema = GenerationCommonConfigSchema.extend({
export const claude35Sonnet = modelRef({
name: 'anthropic/claude-3-5-sonnet',
info: {
versions: ['claude-3-5-sonnet-20240620'],
versions: [
'claude-3-5-sonnet-20240620',
'claude-3-5-sonnet-20241022',
'claude-3-5-sonnet-latest',
],
label: 'Anthropic - Claude 3.5 Sonnet',
supports: {
multiturn: true,
Expand All @@ -84,7 +88,7 @@ export const claude35Sonnet = modelRef({
},
},
configSchema: AnthropicConfigSchema,
version: 'claude-3-5-sonnet-20240620',
version: 'claude-3-5-sonnet-latest',
});

export const claude3Opus = modelRef({
Expand Down Expand Up @@ -138,6 +142,23 @@ export const claude3Haiku = modelRef({
version: 'claude-3-haiku-20240307',
});

export const claude35Haiku = modelRef({
name: 'anthropic/claude-3-5-haiku',
info: {
versions: ['claude-3-5-haiku-20241022', 'claude-3-5-haiku-latest'],
label: 'Anthropic - Claude 3.5 Haiku',
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ['text'],
},
},
configSchema: AnthropicConfigSchema,
version: 'claude-3-5-haiku-latest',
});

export const SUPPORTED_CLAUDE_MODELS: Record<
string,
ModelReference<typeof AnthropicConfigSchema>
Expand All @@ -146,6 +167,7 @@ export const SUPPORTED_CLAUDE_MODELS: Record<
'claude-3-opus': claude3Opus,
'claude-3-sonnet': claude3Sonnet,
'claude-3-haiku': claude3Haiku,
'claude-3-5-haiku': claude35Haiku,
};

/**
Expand Down

0 comments on commit 494947b

Please sign in to comment.