{ "cells": [ { "cell_type": "markdown", "id": "82140df0", "metadata": {}, "source": [ "# ReAct\n", "\n", "This notebook showcases using an agent to implement the ReAct logic." ] }, { "cell_type": "code", "execution_count": 1, "id": "4e272b47", "metadata": {}, "outputs": [], "source": [ "from langchain import OpenAI, Wikipedia\n", "from langchain.agents import initialize_agent, Tool\n", "from langchain.agents.react.base import DocstoreExplorer\n", "docstore=DocstoreExplorer(Wikipedia())\n", "tools = [\n", " Tool(\n", " name=\"Search\",\n", " func=docstore.search\n", " ),\n", " Tool(\n", " name=\"Lookup\",\n", " func=docstore.lookup\n", " )\n", "]\n", "\n", "llm = OpenAI(temperature=0)\n", "react = initialize_agent(tools, llm, agent=\"react-docstore\", verbose=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "8078c8f1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?\n", "Thought 1:" ] } ], "source": [ "question = \"Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?\"\n", "react.run(question)" ] }, { "cell_type": "code", "execution_count": null, "id": "4ff64e81", "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 }