Skip to content

Commit

Permalink
Merge pull request #97 from TheFireCo/feat/claude-3-5-sonnet
Browse files Browse the repository at this point in the history
[Anthropic] Add support for Claude 3.5 Sonnet model
  • Loading branch information
Dabolus authored Jul 10, 2024
2 parents ed8d705 + 33638bd commit f3155e9
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/docs/plugins/anthropic.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Install the plugin in your project with your favorite package manager:
## Supported models

The plugin supports the most recent Anthropic models:
**Claude 3 Opus**, **Claude 3 Sonnet**, and **Claude 3 Haiku**.
**Claude 3.5 Sonnet**, **Claude 3 Opus**, **Claude 3 Sonnet**, and **Claude 3 Haiku**.

## Usage

Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/anthropic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ to the [official Vertex AI plugin](https://www.npmjs.com/package/@genkit-ai/vert
## Supported models

The plugin supports the most recent Anthropic models:
**Claude 3 Opus**, **Claude 3 Sonnet**, and **Claude 3 Haiku**.
**Claude 3.5 Sonnet**, **Claude 3 Opus**, **Claude 3 Sonnet**, and **Claude 3 Haiku**.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion plugins/anthropic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"author": "TheFireCo",
"license": "Apache-2.0",
"dependencies": {
"@anthropic-ai/sdk": "^0.22.0",
"@anthropic-ai/sdk": "^0.24.0",
"zod": "^3.23.8"
},
"peerDependencies": {
Expand Down
33 changes: 33 additions & 0 deletions plugins/anthropic/src/claude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,39 @@ describe('toAnthropicRequestBody', () => {
genkitRequest: GenerateRequest<typeof AnthropicConfigSchema>;
expectedOutput: MessageCreateParams;
}[] = [
{
should: '(claude-3-5-sonnet) handles request with text messages',
modelName: 'claude-3-5-sonnet',
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-sonnet-20240620',
metadata: {
user_id: 'exampleUser123',
},
},
},
{
should: '(claude-3-opus) handles request with text messages',
modelName: 'claude-3-opus',
Expand Down
18 changes: 18 additions & 0 deletions plugins/anthropic/src/claude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ export const AnthropicConfigSchema = GenerationCommonConfigSchema.extend({
.optional(),
});

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

export const claude3Opus = modelRef({
name: 'anthropic/claude-3-opus',
info: {
Expand Down Expand Up @@ -124,6 +141,7 @@ export const SUPPORTED_CLAUDE_MODELS: Record<
string,
ModelReference<typeof AnthropicConfigSchema>
> = {
'claude-3-5-sonnet': claude35Sonnet,
'claude-3-opus': claude3Opus,
'claude-3-sonnet': claude3Sonnet,
'claude-3-haiku': claude3Haiku,
Expand Down
4 changes: 3 additions & 1 deletion plugins/anthropic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import { genkitPlugin, type Plugin } from '@genkit-ai/core';
import Anthropic from '@anthropic-ai/sdk';
import {
claude35Sonnet,
claude3Opus,
claude3Sonnet,
claude3Haiku,
claudeModel,
SUPPORTED_CLAUDE_MODELS,
} from './claude.js';
export { claude3Opus, claude3Sonnet, claude3Haiku };
export { claude35Sonnet, claude3Opus, claude3Sonnet, claude3Haiku };

export interface PluginOptions {
apiKey?: string;
Expand All @@ -37,6 +38,7 @@ export interface PluginOptions {
* environment variables. It initializes the Anthropic client and makes available the Claude models for use.
*
* Exports:
* - claude35Sonnet: Reference to the Claude 3.5 Sonnet model.
* - claude3Haiku: Reference to the Claude 3 Haiku model.
* - claude3Sonnet: Reference to the Claude 3 Sonnet model.
* - claude3Opus: Reference to the Claude 3 Opus model.
Expand Down

0 comments on commit f3155e9

Please sign in to comment.