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

chore(deps)!: bump genkit to 0.9 RC #152

Closed
wants to merge 3 commits into from
Closed
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
1,888 changes: 1,467 additions & 421 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions plugins/anthropic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
},
"author": "TheFireCo",
"license": "Apache-2.0",
"peerDependencies": {
"genkit": "^0.9.0-dev.1"
},
"dependencies": {
"@anthropic-ai/sdk": "^0.24.0",
"zod": "^3.23.8"
},
"peerDependencies": {
"@genkit-ai/ai": "^0.5.0",
"@genkit-ai/core": "^0.5.0"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/node": "^20.12.12",
Expand Down
66 changes: 37 additions & 29 deletions plugins/anthropic/src/claude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,27 @@
* limitations under the License.
*/

import { describe, it, expect } from '@jest/globals';
import {
type GenerateResponseData,
type Part,
type GenerateRequest,
type MessageData,
ToolDefinition,
CandidateData,
describe,
it,
expect,
beforeEach,
afterEach,
jest,
} from '@jest/globals';
import {
GenerateResponseData,
Part,
GenerateRequest,
MessageData,
Role,
} from '@genkit-ai/ai/model';
import * as GenkitAiModel from '@genkit-ai/ai/model';
Genkit,
} from 'genkit';
import {
type Message,
type MessageParam,
type MessageCreateParams,
type MessageStreamEvent,
Message,
MessageParam,
MessageCreateParams,
MessageStreamEvent,
} from '@anthropic-ai/sdk/resources/messages.mjs';
import {
AnthropicConfigSchema,
Expand All @@ -47,11 +52,7 @@ import {
toAnthropicToolResponseContent,
} from './claude';
import Anthropic from '@anthropic-ai/sdk';

jest.mock('@genkit-ai/ai/model', () => ({
...jest.requireActual('@genkit-ai/ai/model'),
defineModel: jest.fn(),
}));
import { CandidateData, ToolDefinition } from 'genkit/model';

describe('toAnthropicRole', () => {
const testCases: {
Expand Down Expand Up @@ -102,7 +103,7 @@ describe('toAnthropicRole', () => {

describe('toAnthropicToolResponseContent', () => {
it('should throw an error for unknown parts', () => {
const part: Part = { data: 'hi' };
const part: Part = { data: 'hi' } as Part;
expect(() => toAnthropicToolResponseContent(part)).toThrowError(
`Invalid genkit part provided to toAnthropicToolResponseContent: {"data":"hi"}`
);
Expand Down Expand Up @@ -397,6 +398,7 @@ describe('toAnthropicMessages', () => {
},
},
];

for (const test of testCases) {
it(test.should, () => {
const actualOutput = toAnthropicMessages(test.inputMessages);
Expand Down Expand Up @@ -795,7 +797,7 @@ describe('toAnthropicRequestBody', () => {
expect(() =>
toAnthropicRequestBody('fake-model', {
messages: [],
})
} as GenerateRequest<typeof AnthropicConfigSchema>)
).toThrowError('Unsupported model: fake-model');
});

Expand All @@ -805,7 +807,7 @@ describe('toAnthropicRequestBody', () => {
messages: [],
tools: [],
output: { format: 'media' },
})
} as GenerateRequest<typeof AnthropicConfigSchema>)
).toThrowError(
'Only text output format is supported for Claude models currently'
);
Expand Down Expand Up @@ -841,7 +843,7 @@ describe('claudeRunner', () => {
messages: {
stream: jest.fn(
() =>
// Simluate Anthropic SDK request streaming
// Simulate Anthropic SDK request streaming
new (class {
isFirstRequest = true;
[Symbol.asyncIterator]() {
Expand Down Expand Up @@ -892,16 +894,22 @@ describe('claudeRunner', () => {
});

describe('claudeModel', () => {
let ai: Genkit;

beforeEach(() => {
ai = {
defineModel: jest.fn(),
} as unknown as Genkit;
});

afterEach(() => {
jest.clearAllMocks();
});

it('should correctly define supported GPT models', () => {
jest
.spyOn(GenkitAiModel, 'defineModel')
.mockImplementation((() => ({})) as any);
claudeModel('claude-3-haiku', {} as Anthropic);
expect(GenkitAiModel.defineModel).toHaveBeenCalledWith(
it('should correctly define supported Claude models', () => {
jest.spyOn(ai, 'defineModel').mockImplementation((() => ({})) as any);
claudeModel(ai, 'claude-3-haiku', {} as Anthropic);
expect(ai.defineModel).toHaveBeenCalledWith(
{
name: claude3Haiku.name,
...claude3Haiku.info,
Expand All @@ -913,7 +921,7 @@ describe('claudeModel', () => {

it('should throw for unsupported models', () => {
expect(() =>
claudeModel('unsupported-model', {} as Anthropic)
claudeModel(ai, 'unsupported-model', {} as Anthropic)
).toThrowError('Unsupported model: unsupported-model');
});
});
Loading