2023-01-27 15:10:26 +00:00
{
"cells": [
{
"cell_type": "markdown",
"id": "991b1cc1",
"metadata": {},
"source": [
"# Loading from LangChainHub\n",
"\n",
"This notebook covers how to load agents from [LangChainHub](https://github.com/hwchase17/langchain-hub)."
]
},
{
"cell_type": "code",
2023-02-18 21:40:43 +00:00
"execution_count": 1,
2023-01-27 15:10:26 +00:00
"id": "bd4450a2",
"metadata": {},
"outputs": [
2023-02-18 21:40:43 +00:00
{
"name": "stderr",
"output_type": "stream",
"text": [
"No `_type` key found, defaulting to `prompt`.\n"
]
},
2023-01-27 15:10:26 +00:00
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
2023-03-02 15:05:14 +00:00
"\u001B[1m> Entering new AgentExecutor chain...\u001B[0m\n",
"\u001B[32;1m\u001B[1;3m Yes.\n",
"Follow up: Who is the reigning men's U.S. Open champion?\u001B[0m\n",
"Intermediate answer: \u001B[36;1m\u001B[1;3m2016 · SUI · Stan Wawrinka ; 2017 · ESP · Rafael Nadal ; 2018 · SRB · Novak Djokovic ; 2019 · ESP · Rafael Nadal.\u001B[0m\n",
"\u001B[32;1m\u001B[1;3mSo the reigning men's U.S. Open champion is Rafael Nadal.\n",
"Follow up: What is Rafael Nadal's hometown?\u001B[0m\n",
"Intermediate answer: \u001B[36;1m\u001B[1;3mIn 2016, he once again showed his deep ties to Mallorca and opened the Rafa Nadal Academy in his hometown of Manacor.\u001B[0m\n",
"\u001B[32;1m\u001B[1;3mSo the final answer is: Manacor, Mallorca, Spain.\u001B[0m\n",
2023-01-27 15:10:26 +00:00
"\n",
2023-03-02 15:05:14 +00:00
"\u001B[1m> Finished chain.\u001B[0m\n"
2023-01-27 15:10:26 +00:00
]
},
{
"data": {
"text/plain": [
"'Manacor, Mallorca, Spain.'"
]
},
2023-02-18 21:40:43 +00:00
"execution_count": 1,
2023-01-27 15:10:26 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain import OpenAI, SerpAPIWrapper\n",
"from langchain.agents import initialize_agent, Tool\n",
"\n",
"llm = OpenAI(temperature=0)\n",
"search = SerpAPIWrapper()\n",
"tools = [\n",
" Tool(\n",
" name=\"Intermediate Answer\",\n",
2023-03-17 04:55:44 +00:00
" func=search.run,\n",
" description=\"useful for when you need to ask with search\"\n",
2023-01-27 15:10:26 +00:00
" )\n",
"]\n",
"\n",
"self_ask_with_search = initialize_agent(tools, llm, agent_path=\"lc://agents/self-ask-with-search/agent.json\", verbose=True)\n",
"self_ask_with_search.run(\"What is the hometown of the reigning men's U.S. Open champion?\")"
]
},
2023-01-30 22:52:17 +00:00
{
"cell_type": "markdown",
"id": "3aede965",
"metadata": {},
"source": [
"# Pinning Dependencies\n",
"\n",
"Specific versions of LangChainHub agents can be pinned with the `lc@<ref>://` syntax."
]
},
2023-01-27 15:10:26 +00:00
{
"cell_type": "code",
2023-02-18 21:40:43 +00:00
"execution_count": 2,
2023-01-27 15:10:26 +00:00
"id": "e679f7b6",
"metadata": {},
2023-02-18 21:40:43 +00:00
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"No `_type` key found, defaulting to `prompt`.\n"
]
}
],
2023-01-30 22:52:17 +00:00
"source": [
"self_ask_with_search = initialize_agent(tools, llm, agent_path=\"lc@2826ef9e8acdf88465e1e5fc8a7bf59e0f9d0a85://agents/self-ask-with-search/agent.json\", verbose=True)"
]
2023-02-18 21:40:43 +00:00
},
{
"cell_type": "code",
"execution_count": null,
"id": "9d3d6697",
"metadata": {},
"outputs": [],
"source": []
2023-01-27 15:10:26 +00:00
}
],
"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",
2023-02-18 21:40:43 +00:00
"version": "3.9.1"
2023-01-27 15:10:26 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 5
}