Files
langchain/docs/modules/agents/tools/examples/openweathermap.ipynb
Honkware aff33d52c5 Add OpenWeatherMap API Tool (#2083)
Added tool for OpenWeatherMap API
2023-03-28 12:02:14 -07:00

3.1 KiB

OpenWeatherMap API

This notebook goes over how to use the OpenWeatherMap component to fetch weather information.

First, you need to sign up for an OpenWeatherMap API key:

  1. Go to OpenWeatherMap and sign up for an API key here
  2. pip install pyowm

Then we will need to set some environment variables:

  1. Save your API KEY into OPENWEATHERMAP_API_KEY env variable
In [ ]:
pip install pyowm
In [35]:
import os
os.environ["OPENWEATHERMAP_API_KEY"] = ""
In [36]:
from langchain.utilities import OpenWeatherMapAPIWrapper
In [37]:
weather = OpenWeatherMapAPIWrapper()
In [38]:
weather_data = weather.run("London,GB")
In [39]:
print(weather_data)
In London,GB, the current weather is as follows:
Detailed status: overcast clouds
Wind speed: 4.63 m/s, direction: 150°
Humidity: 67%
Temperature: 
  - Current: 5.35°C
  - High: 6.26°C
  - Low: 3.49°C
  - Feels like: 1.95°C
Rain: {}
Heat index: None
Cloud cover: 100%