跳到主要内容
此笔记本展示了如何使用代理与 NASA 工具包进行交互。该工具包提供了访问 NASA 图像和视频库 API 的权限,并有可能在未来迭代中扩展以包含其他可访问的 NASA API。 注意:当未指定所需的媒体结果数量时,NASA 图像和视频库的搜索查询可能会导致大量响应。在使用代理与 LLM 令牌额度之前,请考虑这一点。

使用示例


初始化代理

pip install -qU langchain-community
from langchain.agents import AgentType, initialize_agent
from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit
from langchain_community.utilities.nasa import NasaAPIWrapper
from langchain_openai import OpenAI

llm = OpenAI(temperature=0, openai_api_key="")
nasa = NasaAPIWrapper()
toolkit = NasaToolkit.from_nasa_api_wrapper(nasa)
agent = initialize_agent(
    toolkit.get_tools(), llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)

查询媒体资产

agent.run(
    "Can you find three pictures of the moon published between the years 2014 and 2020?"
)

查询媒体资产详情

output = agent.run(
    "I've just queried an image of the moon with the NASA id NHQ_2019_0311_Go Forward to the Moon."
    " Where can I find the metadata manifest for this asset?"
)

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.