Skip to content
Open
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
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 () => {
const { text } = await ai.generate({
model: anthropic.model('claude-sonnet-4-5'),
tools: [getWeather],
prompt: 'What is the weather in Paris?',
});

return text;
});