get-weather
simple-ai/get-weatherFreeUtility
A tool for getting the weather.
Install it
npx shadcn@latest add https://simple-ai.dev/r/get-weather.jsonSource
1import { type InferUITool, tool } from "ai";2import { z } from "zod";34const getWeatherParamsSchema = z.object({5 city: z.string().describe("The city to get the weather for"),6 unit: z.enum(["fahrenheit", "celsius"]).describe("The unit of temperature"),7});89export type GetWeatherParams = z.infer<typeof getWeatherParamsSchema>;1011const getWeatherResultSchema = z.union([12 z.object({13 success: z.literal(true),14 message: z.string(),15 temperature: z.number(),16 windSpeed: z.number(),17 weatherCode: z.number(),18 }),19 z.object({20 success: z.literal(false),21 error: z.string(),22 }),23]);2425export type GetWeatherResult = z.infer<typeof getWeatherResultSchema>;2627export const getWeatherTool = tool({28 name: "get-weather",29 description: "Get the current weather in a location",30 inputSchema: getWeatherParamsSchema,31 outputSchema: getWeatherResultSchema,32 execute: async (params) => {33 try {34 const geocodeUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(params.city)}&count=1&language=en&format=json`;35 const geocodeResponse = await fetch(geocodeUrl);36 const geocodeData = await geocodeResponse.json();3738 if (!geocodeData.results || geocodeData.results.length === 0) {39 return {40 success: false,41 error: `Could not find location: ${params.city}`,42 };43 }4445 const { latitude, longitude } = geocodeData.results[0];4647 const tempUnit =48 params.unit === "celsius" ? "celsius" : "fahrenheit";49 const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,weathercode,windspeed_10m&temperature_unit=${tempUnit}`;50 const weatherResponse = await fetch(weatherUrl);51 const weatherData = await weatherResponse.json();5253 const temperature = weatherData.current.temperature_2m;54 const windSpeed = weatherData.current.windspeed_10m;55 const weatherCode = weatherData.current.weathercode;5657 const weatherDescriptions: Record<number, string> = {58 0: "Clear sky",59 1: "Mainly clear",60 2: "Partly cloudy",61 3: "Overcast",62 45: "Foggy",63 48: "Depositing rime fog",64 51: "Light drizzle",65 53: "Moderate drizzle",66 55: "Dense drizzle",67 61: "Slight rain",68 63: "Moderate rain",69 65: "Heavy rain",70 71: "Slight snow",71 73: "Moderate snow",72 75: "Heavy snow",73 77: "Snow grains",74 80: "Slight rain showers",75 81: "Moderate rain showers",76 82: "Violent rain showers",77 85: "Slight snow showers",78// … truncated
What it pulls in
npm packages
Files it writes
More from simple-ai
All 77 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| agent-respondagent-respond | simple-ai | Utilities | Free | 1 dep | |
| agents-tools-registryagents-tools-registry | simple-ai | Utilities | Free | 1 dep · 2 files | |
| ai-utilsai-utils | simple-ai | Utilities | Free | 1 dep | |
| Exa Agentexa-agent | simple-ai | Utilities | Free | 1 dep | |
| exa-toolexa-tool | simple-ai | Utilities | Free | 3 deps | |
| Firecrawl Agentfirecrawl-agent | simple-ai | Utilities | Free | 1 dep | |
| firecrawl-toolfirecrawl-tool | simple-ai | Utilities | Free | 3 deps | |
| id-to-readable-textid-to-readable-text | simple-ai | Utilities | Free | no deps |
