Skip to content
Open
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 change: 1 addition & 0 deletions js/testapps/anthropic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dev:stable:text-plain": "genkit start -- npx tsx --watch src/stable/text-plain.ts",
"dev:stable:webp": "genkit start -- npx tsx --watch src/stable/webp.ts",
"dev:stable:pdf": "genkit start -- npx tsx --watch src/stable/pdf.ts",
"dev:stable:tools": "genkit start -- npx tsx --watch src/stable/tools.ts",
"genkit:dev": "cross-env GENKIT_ENV=dev npm run dev:stable",
"genkit:start": "cross-env GENKIT_ENV=dev genkit start -- tsx --watch src/stable/basic.ts",
"dev": "export GENKIT_RUNTIME_ID=$(openssl rand -hex 8) && node lib/stable/basic.js 2>&1"
Expand Down
53 changes: 53 additions & 0 deletions js/testapps/anthropic/src/stable/tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2025 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 { anthropic } from '@genkit-ai/anthropic';
import { genkit, z } from 'genkit';

const ai = genkit({
plugins: [
// Configure the plugin with environment-driven API key
anthropic(),
],
});

const getWeather = ai.defineTool(
{
name: 'getWeather',
description: 'Gets the current weather in a given location',
inputSchema: z.object({
location: z
.string()
.describe('The location to get the current weather for'),
}),
outputSchema: z.string(),
},
async (input: any) => {
// Here, we would typically make an API call or database query. For this
// example, we just return a fixed value.
return `The current weather in ${input.location} is 63°F and sunny.`;
}
);

ai.defineFlow('anthropic-stable-tools', async ({ place }) => {
const { text } = await ai.generate({
model: anthropic.model('claude-sonnet-4-5'),
tools: [getWeather],
prompt: `What is the weather in ${place}?`,
});

return text;
});