|
5 | 5 | "id": "9502d5b0", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | | - "# OpenAI Functions Agent\n", |
| 8 | + "# OpenAI Multi Functions Agent\n", |
9 | 9 | "\n", |
10 | 10 | "This notebook showcases using an agent that uses the OpenAI functions ability to respond to the prompts of the user using a Large Language Model\n", |
11 | 11 | "\n", |
|
16 | 16 | }, |
17 | 17 | { |
18 | 18 | "cell_type": "code", |
19 | | - "execution_count": 1, |
| 19 | + "execution_count": 2, |
20 | 20 | "id": "c0a83623", |
21 | 21 | "metadata": {}, |
22 | | - "outputs": [ |
23 | | - { |
24 | | - "name": "stderr", |
25 | | - "output_type": "stream", |
26 | | - "text": [ |
27 | | - "/Users/harrisonchase/.pyenv/versions/3.9.1/envs/langchain/lib/python3.9/site-packages/deeplake/util/check_latest_version.py:32: UserWarning: A newer version of deeplake (3.6.5) is available. It's recommended that you update to the latest version using `pip install -U deeplake`.\n", |
28 | | - " warnings.warn(\n" |
29 | | - ] |
30 | | - } |
31 | | - ], |
| 22 | + "outputs": [], |
32 | 23 | "source": [ |
33 | | - "from langchain import (\n", |
34 | | - " LLMMathChain,\n", |
35 | | - " OpenAI,\n", |
36 | | - " SerpAPIWrapper,\n", |
37 | | - " SQLDatabase,\n", |
38 | | - " SQLDatabaseChain,\n", |
39 | | - ")\n", |
| 24 | + "from langchain import SerpAPIWrapper\n", |
40 | 25 | "from langchain.agents import initialize_agent, Tool\n", |
41 | 26 | "from langchain.agents import AgentType\n", |
42 | 27 | "from langchain.chat_models import ChatOpenAI" |
|
47 | 32 | "id": "86198d9c", |
48 | 33 | "metadata": {}, |
49 | 34 | "source": [ |
50 | | - "The agent is given ability to perform 3 search functionalities with the respective tools\n", |
| 35 | + "The agent is given ability to perform search functionalities with the respective tool\n", |
51 | 36 | "\n", |
52 | 37 | "SerpAPIWrapper:\n", |
53 | | - ">This initializes the SerpAPIWrapper for search functionality (search).\n", |
54 | | - "\n", |
55 | | - "LLMMathChain Initialization:\n", |
56 | | - ">This component provides math-related functionality.\n", |
57 | | - "\n", |
58 | | - "SQL Database Initialization:\n", |
59 | | - ">This component provides the agent to query in Custom Data Base.\n" |
| 38 | + ">This initializes the SerpAPIWrapper for search functionality (search).\n" |
60 | 39 | ] |
61 | 40 | }, |
62 | 41 | { |
63 | 42 | "cell_type": "code", |
64 | | - "execution_count": 2, |
| 43 | + "execution_count": 3, |
65 | 44 | "id": "6fefaba2", |
66 | 45 | "metadata": {}, |
67 | 46 | "outputs": [], |
|
86 | 65 | }, |
87 | 66 | { |
88 | 67 | "cell_type": "code", |
89 | | - "execution_count": 3, |
| 68 | + "execution_count": 4, |
90 | 69 | "id": "9ff6cee9", |
91 | 70 | "metadata": {}, |
92 | 71 | "outputs": [], |
|
128 | 107 | " \"System: You are a helpful AI assistant.\\nHuman: What is the weather in LA and SF?\"\n", |
129 | 108 | " ]\n", |
130 | 109 | "}\n", |
131 | | - "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 2:llm:ChatOpenAI] [2.76s] Exiting LLM run with output:\n", |
| 110 | + "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 2:llm:ChatOpenAI] [2.91s] Exiting LLM run with output:\n", |
132 | 111 | "\u001b[0m{\n", |
133 | 112 | " \"generations\": [\n", |
134 | 113 | " [\n", |
|
160 | 139 | "}\n", |
161 | 140 | "\u001b[32;1m\u001b[1;3m[tool/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:Search] Entering Tool run with input:\n", |
162 | 141 | "\u001b[0m\"{'tool_input': 'weather in Los Angeles'}\"\n", |
163 | | - "\u001b[36;1m\u001b[1;3m[tool/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:Search] [112.99199999999999ms] Exiting Tool run with output:\n", |
| 142 | + "\u001b[36;1m\u001b[1;3m[tool/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 3:tool:Search] [608.693ms] Exiting Tool run with output:\n", |
164 | 143 | "\u001b[0m\"Mostly cloudy early, then sunshine for the afternoon. High 76F. Winds SW at 5 to 10 mph. Humidity59%.\"\n", |
165 | 144 | "\u001b[32;1m\u001b[1;3m[tool/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 4:tool:Search] Entering Tool run with input:\n", |
166 | 145 | "\u001b[0m\"{'tool_input': 'weather in San Francisco'}\"\n", |
167 | | - "\u001b[36;1m\u001b[1;3m[tool/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 4:tool:Search] [522.576ms] Exiting Tool run with output:\n", |
| 146 | + "\u001b[36;1m\u001b[1;3m[tool/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 4:tool:Search] [517.475ms] Exiting Tool run with output:\n", |
168 | 147 | "\u001b[0m\"Partly cloudy this evening, then becoming cloudy after midnight. Low 53F. Winds WSW at 10 to 20 mph. Humidity83%.\"\n", |
169 | 148 | "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 5:llm:ChatOpenAI] Entering LLM run with input:\n", |
170 | 149 | "\u001b[0m{\n", |
171 | 150 | " \"prompts\": [\n", |
172 | 151 | " \"System: You are a helpful AI assistant.\\nHuman: What is the weather in LA and SF?\\nAI: {'name': 'tool_selection', 'arguments': '{\\\\n \\\"actions\\\": [\\\\n {\\\\n \\\"action_name\\\": \\\"Search\\\",\\\\n \\\"action\\\": {\\\\n \\\"tool_input\\\": \\\"weather in Los Angeles\\\"\\\\n }\\\\n },\\\\n {\\\\n \\\"action_name\\\": \\\"Search\\\",\\\\n \\\"action\\\": {\\\\n \\\"tool_input\\\": \\\"weather in San Francisco\\\"\\\\n }\\\\n }\\\\n ]\\\\n}'}\\nFunction: Mostly cloudy early, then sunshine for the afternoon. High 76F. Winds SW at 5 to 10 mph. Humidity59%.\\nAI: {'name': 'tool_selection', 'arguments': '{\\\\n \\\"actions\\\": [\\\\n {\\\\n \\\"action_name\\\": \\\"Search\\\",\\\\n \\\"action\\\": {\\\\n \\\"tool_input\\\": \\\"weather in Los Angeles\\\"\\\\n }\\\\n },\\\\n {\\\\n \\\"action_name\\\": \\\"Search\\\",\\\\n \\\"action\\\": {\\\\n \\\"tool_input\\\": \\\"weather in San Francisco\\\"\\\\n }\\\\n }\\\\n ]\\\\n}'}\\nFunction: Partly cloudy this evening, then becoming cloudy after midnight. Low 53F. Winds WSW at 10 to 20 mph. Humidity83%.\"\n", |
173 | 152 | " ]\n", |
174 | 153 | "}\n", |
175 | | - "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 5:llm:ChatOpenAI] [1.88s] Exiting LLM run with output:\n", |
| 154 | + "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor > 5:llm:ChatOpenAI] [2.33s] Exiting LLM run with output:\n", |
176 | 155 | "\u001b[0m{\n", |
177 | 156 | " \"generations\": [\n", |
178 | 157 | " [\n", |
|
197 | 176 | " },\n", |
198 | 177 | " \"run\": null\n", |
199 | 178 | "}\n", |
200 | | - "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor] [5.28s] Exiting Chain run with output:\n", |
| 179 | + "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[1:chain:AgentExecutor] [6.37s] Exiting Chain run with output:\n", |
201 | 180 | "\u001b[0m{\n", |
202 | 181 | " \"output\": \"The weather in Los Angeles is mostly cloudy with a high of 76°F and a humidity of 59%. The weather in San Francisco is partly cloudy in the evening, becoming cloudy after midnight, with a low of 53°F and a humidity of 83%.\"\n", |
203 | 182 | "}\n" |
|
0 commit comments