OpenWeatherMap
OpenWeatherMap provides all essential weather data for a specific location:
- Current weather
- Minute forecast for 1 hour
- Hourly forecast for 48 hours
- Daily forecast for 8 days
- National weather alerts
- Historical weather data for 40+ years back
此页面介绍如何在 LangChain 中使用 OpenWeatherMap API。
安装与设置
- 使用以下命令安装所需依赖:
pip install pyowm
- 前往OpenWeatherMap并注册账户以获取您的API密钥 这里
- 将您的API密钥设置为
OPENWEATHERMAP_API_KEY环境变量
包装器
工具
存在一个封装了此 API 的 OpenWeatherMapAPIWrapper 工具。要导入此工具:
from langchain_community.utilities.openweathermap import OpenWeatherMapAPIWrapper
API 参考:OpenWeatherMapAPIWrapper
有关此包装器的更详细指南,请参见 这个笔记本。
工具
你还可以轻松将此包装器加载为工具(与代理一起使用)。 你可以通过以下方式实现:
from langchain.agents import load_tools
tools = load_tools(["openweathermap-api"])
API 参考:load_tools
有关工具的更多信息,请参见 此页面。