langchain/docs/docs/integrations/tools/nasa.ipynb
2024-08-08 08:59:02 -07:00

119 lines
3.1 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "e6fd05db-21c2-4227-9900-0840bc62cb31",
"metadata": {},
"source": [
"# NASA Toolkit\n",
"\n",
"This notebook shows how to use agents to interact with the NASA toolkit. The toolkit provides access to the NASA Image and Video Library API, with potential to expand and include other accessible NASA APIs in future iterations.\n",
"\n",
"**Note: NASA Image and Video Library search queries can result in large responses when the number of desired media results is not specified. Consider this prior to using the agent with LLM token credits.**"
]
},
{
"cell_type": "markdown",
"id": "7d93e6bd-03d7-4d3c-b915-8b73164e2ad8",
"metadata": {},
"source": [
"## Example Use:\n",
"---\n",
"### Initializing the agent"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e304b602",
"metadata": {},
"outputs": [],
"source": [
"%pip install -qU langchain-community"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "648a2cb2-308e-4b2e-9b73-37109be4e258",
"metadata": {},
"outputs": [],
"source": [
"from langchain.agents import AgentType, initialize_agent\n",
"from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit\n",
"from langchain_community.utilities.nasa import NasaAPIWrapper\n",
"from langchain_openai import OpenAI\n",
"\n",
"llm = OpenAI(temperature=0, openai_api_key=\"\")\n",
"nasa = NasaAPIWrapper()\n",
"toolkit = NasaToolkit.from_nasa_api_wrapper(nasa)\n",
"agent = initialize_agent(\n",
" toolkit.get_tools(), llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True\n",
")"
]
},
{
"cell_type": "markdown",
"id": "71f05fc9-d80d-4614-b9a3-e0a5e43cbbbb",
"metadata": {},
"source": [
"### Querying media assets"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b97409f3-dc87-425d-b555-406cf8466a28",
"metadata": {},
"outputs": [],
"source": [
"agent.run(\n",
" \"Can you find three pictures of the moon published between the years 2014 and 2020?\"\n",
")"
]
},
{
"cell_type": "markdown",
"id": "a86ce5ff-de45-4206-86ca-07ae03f36bdf",
"metadata": {},
"source": [
"### Querying details about media assets"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80e86b49-749e-4026-b025-db32ed0bcc7e",
"metadata": {},
"outputs": [],
"source": [
"output = agent.run(\n",
" \"I've just queried an image of the moon with the NASA id NHQ_2019_0311_Go Forward to the Moon.\"\n",
" \" Where can I find the metadata manifest for this asset?\"\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}