OpenWeatherMap
OpenWeatherMap 提供特定位置的所有基本天气数据:
- 当前天气
- 1 小时的分钟预报
- 48 小时的每小时预报
- 8 天的每日预报
- 全国天气警报
- 40+ 年前的历史天气数据
本页介绍如何使用OpenWeatherMap API在 LangChain 中。
安装和设置
- 安装要求
pip install pyowm
- 转到 OpenWeatherMap 并注册一个帐户以在此处获取您的 API 密钥
- 将您的 API 密钥设置为
OPENWEATHERMAP_API_KEY环境变量
包装
效用
存在一个包装此 API 的 OpenWeatherMapAPIWrapper 实用程序。要导入此实用程序,请执行以下作:
from langchain_community.utilities.openweathermap import OpenWeatherMapAPIWrapper
API 参考:OpenWeatherMapAPIWrapper
有关此包装器的更详细演练,请参阅此笔记本。
工具
您还可以轻松地将此包装器作为工具加载(与 Agent 一起使用)。 您可以使用以下方法执行此作:
from langchain.agents import load_tools
tools = load_tools(["openweathermap-api"])
API 参考:load_tools
有关工具的更多信息,请参阅此页面。