OpenWeatherMap
OpenWeatherMap 提供特定位置的所有基本天气数据
- 当前天气
- 1小时内每分钟预报
- 48小时内每小时预报
- 8天每日预报
- 国家天气警报
- 40多年来的历史天气数据
本页介绍如何在 LangChain 中使用 OpenWeatherMap API
。
安装与设置
- 安装依赖项:
pip install pyowm
- 前往 OpenWeatherMap 并注册账户以获取您的 API 密钥 此处
- 将您的 API 密钥设置为
OPENWEATHERMAP_API_KEY
环境变量
包装器
实用程序
存在一个 OpenWeatherMapAPIWrapper 实用程序,它封装了这个 API。要导入此实用程序
from langchain_community.utilities.openweathermap import OpenWeatherMapAPIWrapper
API 参考:OpenWeatherMapAPIWrapper
有关此封装器的更详细演练,请参阅此笔记本。
工具
您还可以轻松地将此包装器作为工具(与 Agent 一起使用)加载。您可以通过以下方式实现:
import os
from langchain_community.utilities import OpenWeatherMapAPIWrapper
os.environ["OPENWEATHERMAP_API_KEY"] = ""
weather = OpenWeatherMapAPIWrapper()
tools = [weather.run]
API 参考:OpenWeatherMapAPIWrapper
有关工具的更多信息,请参阅 此页面。