Skip to main content

Prerequisites

This example uses Open-Meteo, which needs no API key and is free for non-commercial use.

Basic Implementation

Usage

The Python and Go tabs on this page assume you have ported the TypeScript tool above; the page does not include those ports. In Python, supply a WeatherInput model, an async get_weather(params, ctx) that returns a model with the fields of the TypeScript outputSchema, and a weather_tool = tool(...) built from them the way weather_tool_with_retry is built under Error Handling. In Go, supply weatherTool, a function declaration shaped like weatherToolWithRetry under Error Handling, and getWeather(city, units string), which returns a struct with those fields and an error. The Go tabs are fragments that belong inside main and call the chat completions API directly.

With Multiple Cities

Extended Version with Forecast

Error Handling

The tool includes proper error handling:

Testing

See Also