|
58 | 58 | }, |
59 | 59 | { |
60 | 60 | "cell_type": "code", |
61 | | - "execution_count": 1, |
| 61 | + "execution_count": 9, |
62 | 62 | "id": "a213e11a-5c62-4ddb-a707-490d91add383", |
63 | 63 | "metadata": {}, |
64 | 64 | "outputs": [], |
|
69 | 69 | }, |
70 | 70 | { |
71 | 71 | "cell_type": "code", |
72 | | - "execution_count": 2, |
| 72 | + "execution_count": 10, |
73 | 73 | "id": "23a1885c-04ab-4750-aefa-105891fddf3e", |
74 | 74 | "metadata": {}, |
75 | | - "outputs": [ |
76 | | - { |
77 | | - "name": "stdin", |
78 | | - "output_type": "stream", |
79 | | - "text": [ |
80 | | - "OPENAI_API_KEY: ········\n" |
81 | | - ] |
82 | | - } |
83 | | - ], |
| 75 | + "outputs": [], |
84 | 76 | "source": [ |
85 | 77 | "import getpass\n", |
86 | 78 | "import os\n", |
|
117 | 109 | }, |
118 | 110 | { |
119 | 111 | "cell_type": "code", |
120 | | - "execution_count": 3, |
| 112 | + "execution_count": 11, |
121 | 113 | "id": "7a154152-973e-4b5d-aa13-48c617744a4c", |
122 | 114 | "metadata": {}, |
123 | | - "outputs": [ |
124 | | - { |
125 | | - "name": "stdout", |
126 | | - "output_type": "stream", |
127 | | - "text": [ |
128 | | - "22:31:51 redisvl.index.index INFO Index already exists, not overwriting.\n", |
129 | | - "22:31:51 redisvl.index.index INFO Index already exists, not overwriting.\n", |
130 | | - "22:31:51 redisvl.index.index INFO Index already exists, not overwriting.\n" |
131 | | - ] |
132 | | - } |
133 | | - ], |
| 115 | + "outputs": [], |
134 | 116 | "source": [ |
135 | | - "from typing import Literal\n", |
136 | | - "\n", |
137 | | - "from langchain_core.tools import tool\n", |
138 | | - "\n", |
139 | 117 | "# First we initialize the model we want to use.\n", |
140 | 118 | "from langchain_openai import ChatOpenAI\n", |
141 | 119 | "\n", |
142 | | - "from langgraph.checkpoint.redis import RedisSaver\n", |
143 | | - "from langgraph.prebuilt import create_react_agent\n", |
144 | | - "\n", |
145 | 120 | "model = ChatOpenAI(model=\"gpt-4o\", temperature=0)\n", |
146 | 121 | "\n", |
147 | 122 | "\n", |
148 | 123 | "# For this tutorial we will use custom tool that returns pre-defined values for weather in two cities (NYC & SF)\n", |
| 124 | + "\n", |
| 125 | + "from typing import Literal\n", |
| 126 | + "\n", |
| 127 | + "from langchain_core.tools import tool\n", |
| 128 | + "\n", |
| 129 | + "\n", |
149 | 130 | "@tool\n", |
150 | 131 | "def get_weather(city: Literal[\"nyc\", \"sf\"]):\n", |
151 | 132 | " \"\"\"Use this to get weather information.\"\"\"\n", |
|
159 | 140 | "\n", |
160 | 141 | "tools = [get_weather]\n", |
161 | 142 | "\n", |
162 | | - "# We can add \"chat memory\" to the graph with LangGraph's Redis checkpointer\n", |
| 143 | + "# We can add \"chat memory\" to the graph with LangGraph's Redi checkpointer\n", |
163 | 144 | "# to retain the chat context between interactions\n", |
164 | | - "\n", |
| 145 | + "from langgraph.checkpoint.redis import RedisSaver\n", |
165 | 146 | "\n", |
166 | 147 | "REDIS_URI = \"redis://redis:6379\"\n", |
167 | 148 | "memory = None\n", |
168 | 149 | "with RedisSaver.from_conn_string(REDIS_URI) as cp:\n", |
169 | | - " cp.setup()\n", |
170 | | - " memory = cp\n", |
| 150 | + " cp.setup()\n", |
| 151 | + " memory = cp\n", |
171 | 152 | "\n", |
172 | 153 | "# Define the graph\n", |
173 | 154 | "\n", |
| 155 | + "from langgraph.prebuilt import create_react_agent\n", |
174 | 156 | "\n", |
175 | 157 | "graph = create_react_agent(model, tools=tools, checkpointer=memory)" |
176 | 158 | ] |
|
187 | 169 | }, |
188 | 170 | { |
189 | 171 | "cell_type": "code", |
190 | | - "execution_count": 4, |
| 172 | + "execution_count": 12, |
191 | 173 | "id": "16636975-5f2d-4dc7-ab8e-d0bea0830a28", |
192 | 174 | "metadata": {}, |
193 | 175 | "outputs": [], |
|
203 | 185 | }, |
204 | 186 | { |
205 | 187 | "cell_type": "code", |
206 | | - "execution_count": 5, |
| 188 | + "execution_count": 13, |
207 | 189 | "id": "9ffff6c3-a4f5-47c9-b51d-97caaee85cd6", |
208 | 190 | "metadata": {}, |
209 | 191 | "outputs": [ |
|
216 | 198 | "What's the weather in NYC?\n", |
217 | 199 | "==================================\u001b[1m Ai Message \u001b[0m==================================\n", |
218 | 200 | "Tool Calls:\n", |
219 | | - " get_weather (call_Edwfw0WiyIJ7vt9xzU9xvyeg)\n", |
220 | | - " Call ID: call_Edwfw0WiyIJ7vt9xzU9xvyeg\n", |
| 201 | + " get_weather (call_RHv6T6OBCn7eKOlm5qEpLK4P)\n", |
| 202 | + " Call ID: call_RHv6T6OBCn7eKOlm5qEpLK4P\n", |
221 | 203 | " Args:\n", |
222 | 204 | " city: nyc\n", |
223 | 205 | "=================================\u001b[1m Tool Message \u001b[0m=================================\n", |
|
247 | 229 | }, |
248 | 230 | { |
249 | 231 | "cell_type": "code", |
250 | | - "execution_count": 6, |
| 232 | + "execution_count": 14, |
251 | 233 | "id": "187479f9-32fa-4611-9487-cf816ba2e147", |
252 | 234 | "metadata": {}, |
253 | 235 | "outputs": [ |
|
260 | 242 | "What's it known for?\n", |
261 | 243 | "==================================\u001b[1m Ai Message \u001b[0m==================================\n", |
262 | 244 | "\n", |
263 | | - "Could you please specify what \"it\" refers to? Are you asking about a specific city, person, event, or something else?\n" |
| 245 | + "Could you please specify what \"it\" refers to? Are you asking about a specific place, person, event, or something else?\n" |
264 | 246 | ] |
265 | 247 | } |
266 | 248 | ], |
|
0 commit comments