Skip to content

Instantly share code, notes, and snippets.

@peterfriese
Created May 31, 2024 12:52
Show Gist options
  • Save peterfriese/90bf933c3236f664912431609d4e03df to your computer and use it in GitHub Desktop.
Save peterfriese/90bf933c3236f664912431609d4e03df to your computer and use it in GitHub Desktop.
import {defineTool, generate} from '@genkit-ai/ai';
import {configureGenkit} from '@genkit-ai/core';
import {gemini15ProPreview} from '@genkit-ai/vertexai';
import * as z from 'zod';
import {vertexAI} from '@genkit-ai/vertexai';
configureGenkit({
plugins: [
vertexAI({location: 'us-central1'}),
],
logLevel: 'error',
enableTracingAndMetrics: true,
});
const weather = defineTool(
{
name: 'weather',
description: 'Use this to determine the weather in a given location.',
inputSchema: z.object({
location: z.string().describe('The location to get the weather for.'),
}),
outputSchema: z.object({
location: z.string().describe('The location to get the weather for.'),
temperature: z.number().describe('The temperature in celsius.')
})
},
async ({location}) => {
console.log(`Getting the weather for ${location}`);
return {
location,
temperature: Number((Math.random() * (45 - -20) + -20).toFixed(1))
}
}
);
(async () => {
const result = await generate({
model: gemini15ProPreview,
prompt: 'What is the weather in New York City?',
tools: [weather]
});
console.log(result.text());
})();
// Output:
// Getting the weather for New York City
// The weather in New York City is - 5.7 degrees.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment