Genkit MCP
Official
by firebase
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
Message,
MessageCreateParamsBase,
} from '@anthropic-ai/sdk/resources/messages.mjs';
import * as assert from 'assert';
import { GenerateRequest, GenerateResponseData } from 'genkit';
import { describe, it } from 'node:test';
import {
AnthropicConfigSchema,
fromAnthropicResponse,
toAnthropicRequest,
} from '../../src/modelgarden/anthropic';
const MODEL_ID = 'modelid';
describe('toAnthropicRequest', () => {
const testCases: {
should: string;
input: GenerateRequest<typeof AnthropicConfigSchema>;
expectedOutput: MessageCreateParamsBase;
}[] = [
{
should: 'should transform genkit message (text content) correctly',
input: {
messages: [
{
role: 'user',
content: [{ text: 'Tell a joke about dogs.' }],
},
],
},
expectedOutput: {
max_tokens: 4096,
model: MODEL_ID,
messages: [
{
role: 'user',
content: [{ type: 'text', text: 'Tell a joke about dogs.' }],
},
],
},
},
{
should: 'should transform system message',
input: {
messages: [
{
role: 'system',
content: [{ text: 'Talk like a pirate.' }],
},
{
role: 'user',
content: [{ text: 'Tell a joke about dogs.' }],
},
],
},
expectedOutput: {
max_tokens: 4096,
model: MODEL_ID,
system: 'Talk like a pirate.',
messages: [
{
role: 'user',
content: [{ type: 'text', text: 'Tell a joke about dogs.' }],
},
],
},
},
{
should:
'should transform genkit message (inline base64 image content) correctly',
input: {
messages: [
{
role: 'user',
content: [
{ text: 'describe the following image:' },
{
media: {
contentType: 'image/jpeg',
url: 'data:image/jpeg;base64,/9j/4QDeRXhpZgAASUkqAAgAAAAGABIBAwABAAAAAQAAABoBBQABAAAAVgAAABsBBQABAAAAXgAAACgBAwABAAAAAgAAABMCAwAB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7ynhG/SI8IGNsB6sbk8vqDZKG+j6ZYbl5931KXuPqyo2neTvJ3kU5Z3k7yPWS/Vi+rHHcXUvL9YjzFHMt6y5YAARJvmbuwC9V6xSp4Cg4sgxadq/qLhYuUVX6QgoE2Gr8pYcZ5ikLipaWixb1guoo3LUje7mes9Y7h1uevhzmUdQtBBRWcVOPmYMyO58oOrkcWEwC6HJ9R9ptZ7+IMdQ4pedbilJAdquJXNxSoAtxQlzJFx5ziZYmo1d0yqWSyIvmWTNi0XqlYhZRWQeo/UeBDBMwXmUXrU/wAMQylncn6hxS8BA8q+0K6DjZ8S9gCXeoA0V7QTxHKn4le8v1MStQFR733iThlb1G+os7xFZqNCiFvFRVQ7os8mCnVlSrQTZksBafGFMbFabqDpQDANvh5t+8b4RwWOb5sls01QtHzqcUUqD69YMXdONZAm6W5YvLfvADSssaHrG3cC8S3al3BKOBlhf3lCEYUYX0gnSgVwhj1ktsCf/9k=',
},
},
],
},
],
},
expectedOutput: {
max_tokens: 4096,
model: MODEL_ID,
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'describe the following image:' },
{
type: 'image',
source: {
type: 'base64',
media_type: 'image/jpeg',
data: '/9j/4QDeRXhpZgAASUkqAAgAAAAGABIBAwABAAAAAQAAABoBBQABAAAAVgAAABsBBQABAAAAXgAAACgBAwABAAAAAgAAABMCAwABAAAAAQAAAGmHBAABAAAAZgAAAAAAAABIAAAAAQAAAEgAAAABAAAABwAAkAcABAAAADAyMTABkQcABAAAAAECAwCGkgcAFgAAAMAAAAAAoAcABAAAADAxMDABoAMAAQAAAP//AAACoAQAAQAAAMgAAAADoAQAAQAAAMgAAAAAAAAAQVNDSUkAAABQaWNzdW0gSUQ6IDY4N//bAEMACAYGBwYFCAcHBwkJCAoMFA0MCwsMGRITDxQdGh8eHRocHCAkLicgIiwjHBwoNyksMDE0NDQfJzk9ODI8LjM0Mv/bAEMBCQkJDAsMGA0NGDIhHCEyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy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StQFR733iThlb1G+os7xFZqNCiFvFRVQ7os8mCnVlSrQTZksBafGFMbFabqDpQDANvh5t+8b4RwWOb5sls01QtHzqcUUqD69YMXdONZAm6W5YvLfvADSssaHrG3cC8S3al3BKOBlhf3lCEYUYX0gnSgVwhj1ktsCf/9k=',
},
},
],
},
],
},
},
];
for (const test of testCases) {
it(test.should, () => {
assert.deepEqual(
toAnthropicRequest(MODEL_ID, test.input),
test.expectedOutput
);
});
}
});
describe('fromAnthropicResponse', () => {
const testCases: {
should: string;
input: GenerateRequest<typeof AnthropicConfigSchema>;
response: Message;
expectedOutput: GenerateResponseData;
}[] = [
{
should: 'should transform genkit message (text content) correctly',
input: {
messages: [
{
role: 'user',
content: [{ text: 'Tell a joke about dogs.' }],
},
],
},
response: {
id: 'abcd1234',
model: MODEL_ID,
role: 'assistant',
stop_reason: 'end_turn',
usage: {
input_tokens: 123,
output_tokens: 234,
},
stop_sequence: null,
type: 'message',
content: [
{
type: 'text',
text: 'part 1',
},
{
type: 'text',
text: 'part 2',
},
],
},
expectedOutput: {
custom: {
id: 'abcd1234',
model: MODEL_ID,
type: 'message',
},
finishReason: 'stop',
message: {
role: 'model',
content: [
{
text: 'part 1',
},
{
text: 'part 2',
},
],
},
usage: {
inputAudioFiles: 0,
inputCharacters: 23,
inputImages: 0,
inputTokens: 123,
inputVideos: 0,
outputAudioFiles: 0,
outputCharacters: 12,
outputImages: 0,
outputTokens: 234,
outputVideos: 0,
},
},
},
{
should: 'should transform genkit tool call correctly',
input: {
messages: [
{
role: 'user',
content: [{ text: "What's the weather like today?" }],
},
],
tools: [
{
name: 'get_weather',
description: 'Get the weather for a location.',
inputSchema: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
},
required: ['location'],
},
},
],
},
response: {
id: 'abcd1234',
model: MODEL_ID,
role: 'assistant',
type: 'message',
stop_reason: 'tool_use',
stop_sequence: null,
usage: {
input_tokens: 123,
output_tokens: 234,
},
content: [
{
id: 'toolu_get_weather',
name: 'get_weather',
type: 'tool_use',
input: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
},
required: ['location'],
},
},
],
},
expectedOutput: {
custom: {
id: 'abcd1234',
model: MODEL_ID,
type: 'message',
},
finishReason: 'stop',
message: {
role: 'model',
content: [
{
toolRequest: {
name: 'get_weather',
ref: 'toolu_get_weather',
input: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
},
required: ['location'],
},
},
},
],
},
usage: {
inputAudioFiles: 0,
inputCharacters: 30,
inputImages: 0,
inputTokens: 123,
inputVideos: 0,
outputAudioFiles: 0,
outputCharacters: 0,
outputImages: 0,
outputTokens: 234,
outputVideos: 0,
},
},
},
];
for (const test of testCases) {
it(test.should, () => {
assert.deepEqual(
fromAnthropicResponse(test.input, test.response),
test.expectedOutput
);
});
}
});