2022-10-24 21:51:15 +00:00
|
|
|
{
|
|
|
|
"cells": [
|
2022-11-14 04:13:23 +00:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"id": "0c3f1df8",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"# Self Ask With Search\n",
|
|
|
|
"\n",
|
|
|
|
"This notebook showcases the Self Ask With Search chain."
|
|
|
|
]
|
|
|
|
},
|
2022-10-24 21:51:15 +00:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 1,
|
|
|
|
"id": "7e3b513e",
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
2022-11-14 04:13:23 +00:00
|
|
|
"What is the hometown of the reigning men's U.S. Open champion?\n",
|
2022-11-22 14:16:26 +00:00
|
|
|
"Are follow up questions needed here:\u001b[32;1m\u001b[1;3m Yes.\n",
|
2022-11-14 04:13:23 +00:00
|
|
|
"Follow up: Who is the reigning men's U.S. Open champion?\u001b[0m\n",
|
2022-11-22 14:16:26 +00:00
|
|
|
"Intermediate answer: \u001b[36;1m\u001b[1;3mCarlos Alcaraz\u001b[0m\n",
|
|
|
|
"\u001b[32;1m\u001b[1;3mFollow up: Where is Carlos Alcaraz from?\u001b[0m\n",
|
|
|
|
"Intermediate answer: \u001b[36;1m\u001b[1;3mEl Palmar, Spain\u001b[0m\n",
|
|
|
|
"\u001b[32;1m\u001b[1;3mSo the final answer is: El Palmar, Spain\u001b[0m"
|
2022-10-24 21:51:15 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
2022-11-22 14:16:26 +00:00
|
|
|
"'El Palmar, Spain'"
|
2022-10-24 21:51:15 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
"execution_count": 1,
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2022-11-22 14:16:26 +00:00
|
|
|
"from langchain import OpenAI, SerpAPIChain\n",
|
|
|
|
"from langchain.agents import initialize_agent, Tool\n",
|
2022-10-24 21:51:15 +00:00
|
|
|
"\n",
|
|
|
|
"llm = OpenAI(temperature=0)\n",
|
|
|
|
"search = SerpAPIChain()\n",
|
2022-11-22 14:16:26 +00:00
|
|
|
"tools = [\n",
|
|
|
|
" Tool(\n",
|
|
|
|
" name=\"Intermediate Answer\",\n",
|
|
|
|
" func=search.run\n",
|
|
|
|
" )\n",
|
|
|
|
"]\n",
|
2022-10-24 21:51:15 +00:00
|
|
|
"\n",
|
2022-11-23 02:02:20 +00:00
|
|
|
"self_ask_with_search = initialize_agent(tools, llm, agent=\"self-ask-with-search\", verbose=True)\n",
|
2022-10-24 21:51:15 +00:00
|
|
|
"\n",
|
|
|
|
"self_ask_with_search.run(\"What is the hometown of the reigning men's U.S. Open champion?\")"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
2022-11-14 04:13:23 +00:00
|
|
|
"id": "683d69e7",
|
2022-10-24 21:51:15 +00:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": []
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"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.7.6"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 5
|
|
|
|
}
|