Created
May 31, 2024 12:52
-
-
Save peterfriese/90bf933c3236f664912431609d4e03df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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