OpenWeather
OpenWeatherTools enable an Agent to access weather data from the OpenWeatherMap API.
Prerequisites
The following example requires the requests library and an API key which can be obtained from OpenWeatherMap. Once you sign up the mentioned api key will be activated in a few hours so please be patient.
1export OPENWEATHER_API_KEY=***Example
The following agent will use OpenWeatherMap to get current weather information for Tokyo.
1from kern.agent import Agent2from kern.tools.openweather import OpenWeatherTools34# Create an agent with OpenWeatherTools5agent = Agent(6 tools=[7 OpenWeatherTools(8 units="imperial", # Options: 'standard', 'metric', 'imperial'9 )10 ],11 markdown=True,12)1314# Get current weather for a location15agent.print_response("What's the current weather in Tokyo?", markdown=True)Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | None | OpenWeatherMap API key. If not provided, uses OPENWEATHER_API_KEY env var. |
units | str | metric | Units of measurement. Options: 'standard', 'metric', 'imperial'. |
enable_current_weather | bool | True | Enable current weather function. |
enable_forecast | bool | True | Enable forecast function. |
enable_air_pollution | bool | True | Enable air pollution function. |
enable_geocoding | bool | True | Enable geocoding function. |
Toolkit Functions
| Function | Description |
|---|---|
get_current_weather | Gets current weather data for a location. Takes a location name (e.g., "London"). |
get_forecast | Gets weather forecast for a location. Takes a location name and optional number of days (default 5). |
get_air_pollution | Gets current air pollution data for a location. Takes a location name. |
geocode_location | Converts a location name to geographic coordinates. Takes a location name and optional result limit. |
Developer Resources
- View Tools