From 03aa491f195b7cb8886e15dafc6ba60b12e9d8e0 Mon Sep 17 00:00:00 2001 From: Vaibhav Khating <85737835+vaibhav1663@users.noreply.github.com> Date: Sun, 19 Jan 2025 21:25:50 +0530 Subject: [PATCH 1/2] Fixed weather prompt not working issue --- app/(chat)/api/chat/route.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/(chat)/api/chat/route.ts b/app/(chat)/api/chat/route.ts index 32f0eb0..290ac06 100644 --- a/app/(chat)/api/chat/route.ts +++ b/app/(chat)/api/chat/route.ts @@ -58,13 +58,24 @@ export async function POST(request: Request) { getWeather: { description: "Get the current weather at a location", parameters: z.object({ - latitude: z.number().describe("Latitude coordinate"), - longitude: z.number().describe("Longitude coordinate"), + city: z.string().describe("Name of the city"), }), - execute: async ({ latitude, longitude }) => { + execute: async ({ city }) => { + const geoResponse = await fetch( + `https://nominatim.openstreetmap.org/search?city=${encodeURIComponent(city)}&format=json&limit=1` + ); + const geoData = await geoResponse.json(); + console.log(geoData); + if (!geoData.length) { + throw new Error("City not found"); + } + + const { lat, lon } = geoData[0]; // Extract latitude and longitude + const response = await fetch( - `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`, + `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`, ); + console.log(response); const weatherData = await response.json(); return weatherData; From 4128230955ab82127782fe7be5b6fbdb5c8fa081 Mon Sep 17 00:00:00 2001 From: Vaibhav Khating <85737835+vaibhav1663@users.noreply.github.com> Date: Sun, 19 Jan 2025 21:28:18 +0530 Subject: [PATCH 2/2] removed console logs --- app/(chat)/api/chat/route.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/(chat)/api/chat/route.ts b/app/(chat)/api/chat/route.ts index 290ac06..6d6b590 100644 --- a/app/(chat)/api/chat/route.ts +++ b/app/(chat)/api/chat/route.ts @@ -65,7 +65,6 @@ export async function POST(request: Request) { `https://nominatim.openstreetmap.org/search?city=${encodeURIComponent(city)}&format=json&limit=1` ); const geoData = await geoResponse.json(); - console.log(geoData); if (!geoData.length) { throw new Error("City not found"); } @@ -75,7 +74,6 @@ export async function POST(request: Request) { const response = await fetch( `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t=temperature_2m&hourly=temperature_2m&daily=sunrise,sunset&timezone=auto`, ); - console.log(response); const weatherData = await response.json(); return weatherData;