refactor: use tool() and organize by file (#721)

Co-authored-by: Marcus Schiesser <mail@marcusschiesser.de>
This commit is contained in:
Jeremy 2025-01-23 01:19:48 +05:30 committed by GitHub
parent 371242d683
commit 3f9d379a6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 412 additions and 345 deletions

View file

@ -0,0 +1,18 @@
import { tool } from 'ai';
import { z } from 'zod';
export const getWeather = tool({
description: 'Get the current weather at a location',
parameters: z.object({
latitude: z.number(),
longitude: z.number(),
}),
execute: async ({ latitude, longitude }) => {
const response = await fetch(
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`,
);
const weatherData = await response.json();
return weatherData;
},
});