|
40 | 40 | }, |
41 | 41 | { |
42 | 42 | "cell_type": "code", |
43 | | - "execution_count": 18, |
| 43 | + "execution_count": null, |
44 | 44 | "metadata": {}, |
45 | | - "outputs": [ |
46 | | - { |
47 | | - "name": "stdout", |
48 | | - "output_type": "stream", |
49 | | - "text": [ |
50 | | - "\n", |
51 | | - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.0.1\u001b[0m\n", |
52 | | - "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", |
53 | | - "Note: you may need to restart the kernel to use updated packages.\n" |
54 | | - ] |
55 | | - } |
56 | | - ], |
| 45 | + "outputs": [], |
57 | 46 | "source": [ |
58 | 47 | "%pip install -q langchain-openai langgraph-checkpoint langgraph-checkpoint-redis \"langchain-community>=0.2.11\" tavily-python langchain-redis pydantic ulid" |
59 | 48 | ] |
|
85 | 74 | "\n", |
86 | 75 | "\n", |
87 | 76 | "_set_env(\"OPENAI_API_KEY\")\n", |
88 | | - "_set_env(\"TAVILY_API_KEY\")" |
| 77 | + "\n", |
| 78 | + "# Uncomment this if you have a Tavily API key and want to\n", |
| 79 | + "# use the web search tool.\n", |
| 80 | + "# _set_env(\"TAVILY_API_KEY\")" |
89 | 81 | ] |
90 | 82 | }, |
91 | 83 | { |
|
134 | 126 | }, |
135 | 127 | { |
136 | 128 | "cell_type": "code", |
137 | | - "execution_count": 11, |
| 129 | + "execution_count": null, |
138 | 130 | "metadata": {}, |
139 | | - "outputs": [ |
140 | | - { |
141 | | - "data": { |
142 | | - "text/plain": [ |
143 | | - "True" |
144 | | - ] |
145 | | - }, |
146 | | - "execution_count": 11, |
147 | | - "metadata": {}, |
148 | | - "output_type": "execute_result" |
149 | | - } |
150 | | - ], |
| 131 | + "outputs": [], |
151 | 132 | "source": [ |
152 | 133 | "import os\n", |
153 | 134 | "from redis import Redis\n", |
|
335 | 316 | }, |
336 | 317 | { |
337 | 318 | "cell_type": "code", |
338 | | - "execution_count": 13, |
| 319 | + "execution_count": null, |
339 | 320 | "metadata": {}, |
340 | | - "outputs": [ |
341 | | - { |
342 | | - "name": "stdout", |
343 | | - "output_type": "stream", |
344 | | - "text": [ |
345 | | - "16:49:44 redisvl.index.index INFO Index already exists, not overwriting.\n", |
346 | | - "Long-term memory index ready\n" |
347 | | - ] |
348 | | - } |
349 | | - ], |
| 321 | + "outputs": [], |
350 | 322 | "source": [ |
351 | 323 | "from redisvl.index import SearchIndex\n", |
352 | 324 | "from redisvl.schema.schema import IndexSchema\n", |
|
409 | 381 | }, |
410 | 382 | { |
411 | 383 | "cell_type": "code", |
412 | | - "execution_count": 14, |
| 384 | + "execution_count": null, |
413 | 385 | "metadata": {}, |
414 | | - "outputs": [ |
415 | | - { |
416 | | - "ename": "ValueError", |
417 | | - "evalue": "OpenAI API key is required. Provide it in api_config or set the OPENAI_API_KEY environment variable.", |
418 | | - "output_type": "error", |
419 | | - "traceback": [ |
420 | | - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
421 | | - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", |
422 | | - "Cell \u001b[0;32mIn[14], line 13\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;66;03m# If we have any memories that aren't associated with a user, we'll use this ID.\u001b[39;00m\n\u001b[1;32m 11\u001b[0m SYSTEM_USER_ID \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msystem\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m---> 13\u001b[0m openai_embed \u001b[38;5;241m=\u001b[39m \u001b[43mOpenAITextVectorizer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtext-embedding-ada-002\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;66;03m# Change this to MemoryStrategy.TOOLS to use function-calling to store and\u001b[39;00m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;66;03m# retrieve memories.\u001b[39;00m\n\u001b[1;32m 17\u001b[0m memory_strategy \u001b[38;5;241m=\u001b[39m MemoryStrategy\u001b[38;5;241m.\u001b[39mMANUAL\n", |
423 | | - "File \u001b[0;32m~/src/redis-ai-resources/env/lib/python3.11/site-packages/redisvl/utils/vectorize/text/openai.py:75\u001b[0m, in \u001b[0;36mOpenAITextVectorizer.__init__\u001b[0;34m(self, model, api_config, dtype, **kwargs)\u001b[0m\n\u001b[1;32m 73\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(model\u001b[38;5;241m=\u001b[39mmodel, dtype\u001b[38;5;241m=\u001b[39mdtype)\n\u001b[1;32m 74\u001b[0m \u001b[38;5;66;03m# Init clients\u001b[39;00m\n\u001b[0;32m---> 75\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_initialize_clients\u001b[49m\u001b[43m(\u001b[49m\u001b[43mapi_config\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 76\u001b[0m \u001b[38;5;66;03m# Set model dimensions after init\u001b[39;00m\n\u001b[1;32m 77\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdims \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_set_model_dims()\n", |
424 | | - "File \u001b[0;32m~/src/redis-ai-resources/env/lib/python3.11/site-packages/redisvl/utils/vectorize/text/openai.py:100\u001b[0m, in \u001b[0;36mOpenAITextVectorizer._initialize_clients\u001b[0;34m(self, api_config, **kwargs)\u001b[0m\n\u001b[1;32m 96\u001b[0m api_key \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m 97\u001b[0m api_config\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapi_key\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mif\u001b[39;00m api_config \u001b[38;5;28;01melse\u001b[39;00m os\u001b[38;5;241m.\u001b[39mgetenv(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOPENAI_API_KEY\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 98\u001b[0m )\n\u001b[1;32m 99\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m api_key:\n\u001b[0;32m--> 100\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 101\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOpenAI API key is required. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 102\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mProvide it in api_config or set the OPENAI_API_KEY\u001b[39m\u001b[38;5;130;01m\\\u001b[39;00m\n\u001b[1;32m 103\u001b[0m \u001b[38;5;124m environment variable.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 104\u001b[0m )\n\u001b[1;32m 106\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_client \u001b[38;5;241m=\u001b[39m OpenAI(api_key\u001b[38;5;241m=\u001b[39mapi_key, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mapi_config, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 107\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_aclient \u001b[38;5;241m=\u001b[39m AsyncOpenAI(api_key\u001b[38;5;241m=\u001b[39mapi_key, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mapi_config, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", |
425 | | - "\u001b[0;31mValueError\u001b[0m: OpenAI API key is required. Provide it in api_config or set the OPENAI_API_KEY environment variable." |
426 | | - ] |
427 | | - } |
428 | | - ], |
| 386 | + "outputs": [], |
429 | 387 | "source": [ |
430 | 388 | "import logging\n", |
431 | 389 | "\n", |
|
1113 | 1071 | "llm = ChatOpenAI(model=\"gpt-4o\", temperature=0.7)\n", |
1114 | 1072 | "\n", |
1115 | 1073 | "\n", |
1116 | | - "web_search_tool = CachingTavilySearchResults(max_results=2)\n", |
1117 | | - "base_tools = [web_search_tool]\n", |
| 1074 | + "# Uncomment these lines if you have a Tavily API key and want to use the web\n", |
| 1075 | + "# search tool. The agent is much more useful with this tool.\n", |
| 1076 | + "# web_search_tool = CachingTavilySearchResults(max_results=2)\n", |
| 1077 | + "# base_tools = [web_search_tool]\n", |
| 1078 | + "base_tools = []\n", |
| 1079 | + "\n", |
1118 | 1080 | "if memory_strategy == MemoryStrategy.TOOLS:\n", |
1119 | 1081 | " tools = base_tools + [store_memory_tool, retrieve_memories_tool]\n", |
1120 | 1082 | "elif memory_strategy == MemoryStrategy.MANUAL:\n", |
|
0 commit comments