Skip to content

Commit ce6002e

Browse files
committed
Fix typo
1 parent 6f7ca65 commit ce6002e

File tree

1 file changed

+29
-92
lines changed

1 file changed

+29
-92
lines changed

python-recipes/agents/03_memory_agent.ipynb

Lines changed: 29 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
{
4242
"cell_type": "code",
43-
"execution_count": 82,
43+
"execution_count": 18,
4444
"metadata": {},
4545
"outputs": [
4646
{
@@ -70,7 +70,7 @@
7070
},
7171
{
7272
"cell_type": "code",
73-
"execution_count": 83,
73+
"execution_count": 19,
7474
"metadata": {},
7575
"outputs": [],
7676
"source": [
@@ -101,7 +101,7 @@
101101
},
102102
{
103103
"cell_type": "code",
104-
"execution_count": 84,
104+
"execution_count": 10,
105105
"metadata": {},
106106
"outputs": [],
107107
"source": [
@@ -134,7 +134,7 @@
134134
},
135135
{
136136
"cell_type": "code",
137-
"execution_count": 85,
137+
"execution_count": 11,
138138
"metadata": {},
139139
"outputs": [
140140
{
@@ -143,12 +143,13 @@
143143
"True"
144144
]
145145
},
146-
"execution_count": 85,
146+
"execution_count": 11,
147147
"metadata": {},
148148
"output_type": "execute_result"
149149
}
150150
],
151151
"source": [
152+
"import os\n",
152153
"from redis import Redis\n",
153154
"\n",
154155
"# Use the environment variable if set, otherwise default to localhost\n",
@@ -222,7 +223,7 @@
222223
},
223224
{
224225
"cell_type": "code",
225-
"execution_count": 86,
226+
"execution_count": 12,
226227
"metadata": {},
227228
"outputs": [],
228229
"source": [
@@ -334,14 +335,14 @@
334335
},
335336
{
336337
"cell_type": "code",
337-
"execution_count": 87,
338+
"execution_count": 13,
338339
"metadata": {},
339340
"outputs": [
340341
{
341342
"name": "stdout",
342343
"output_type": "stream",
343344
"text": [
344-
"16:25:36 redisvl.index.index INFO Index already exists, not overwriting.\n",
345+
"16:49:44 redisvl.index.index INFO Index already exists, not overwriting.\n",
345346
"Long-term memory index ready\n"
346347
]
347348
}
@@ -408,9 +409,23 @@
408409
},
409410
{
410411
"cell_type": "code",
411-
"execution_count": 88,
412+
"execution_count": 14,
412413
"metadata": {},
413-
"outputs": [],
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+
],
414429
"source": [
415430
"import logging\n",
416431
"\n",
@@ -1048,19 +1063,9 @@
10481063
},
10491064
{
10501065
"cell_type": "code",
1051-
"execution_count": 95,
1066+
"execution_count": null,
10521067
"metadata": {},
1053-
"outputs": [
1054-
{
1055-
"name": "stdout",
1056-
"output_type": "stream",
1057-
"text": [
1058-
"16:25:36 redisvl.index.index INFO Index already exists, not overwriting.\n",
1059-
"16:25:36 redisvl.index.index INFO Index already exists, not overwriting.\n",
1060-
"16:25:36 redisvl.index.index INFO Index already exists, not overwriting.\n"
1061-
]
1062-
}
1063-
],
1068+
"outputs": [],
10641069
"source": [
10651070
"import json\n",
10661071
"from typing import Dict, List, Optional, Tuple, Union\n",
@@ -1519,77 +1524,9 @@
15191524
},
15201525
{
15211526
"cell_type": "code",
1522-
"execution_count": 101,
1527+
"execution_count": null,
15231528
"metadata": {},
1524-
"outputs": [
1525-
{
1526-
"name": "stdout",
1527-
"output_type": "stream",
1528-
"text": [
1529-
"Welcome to the Travel Assistant! (Type 'exit' to quit)\n",
1530-
"\n",
1531-
"Assistant: In April, there are some fantastic destinations around the world, especially for enjoying springtime beauty and unique events. Here are my top 5 recommendations for travel in April:\n",
1532-
"\n",
1533-
"1. **Japan**: \n",
1534-
" - **Kyoto**: Experience the cherry blossoms at iconic sites such as the Philosopher's Path and Maruyama Park. Kyoto's blend of traditional culture and stunning natural beauty makes it a must-visit.\n",
1535-
"\n",
1536-
"2. **Amsterdam, Netherlands**: \n",
1537-
" - **Tulip Festival**: April is the perfect time to visit the Keukenhof Gardens and see the world-famous tulip fields in full bloom. The city also boasts beautiful canals and rich historical sites.\n",
1538-
"\n",
1539-
"3. **Washington, D.C., USA**: \n",
1540-
" - **National Cherry Blossom Festival**: This festival celebrates the blooming of cherry trees gifted from Japan, creating a picturesque scene around the National Mall and Tidal Basin.\n",
1541-
"\n",
1542-
"4. **Paris, France**: \n",
1543-
" - **Springtime in Paris**: The city blooms with flowers and is less crowded than in summer. Enjoy the beautiful parks like Jardin des Tuileries and cultural sites such as the Louvre and Eiffel Tower.\n",
1544-
"\n",
1545-
"5. **Morocco**: \n",
1546-
" - **Fez and Marrakech**: April offers pleasant weather to explore the vibrant markets, historic medinas, and stunning deserts. The cultural richness and architecture are highlights.\n",
1547-
"\n",
1548-
"These destinations offer a mix of natural beauty, cultural experiences, and unique seasonal events, making them perfect for a memorable April getaway. If you have specific preferences or interests, let me know, and I can refine these suggestions further!\n",
1549-
"\n",
1550-
"Assistant: No problem! Here are the top 5 places to visit in Japan during April, especially to enjoy the cherry blossom season and other unique experiences:\n",
1551-
"\n",
1552-
"1. **Kyoto**:\n",
1553-
" - **Philosopher's Path**: This picturesque canal-side walkway is lined with cherry trees, offering a serene setting for a spring stroll.\n",
1554-
" - **Kiyomizu-dera**: A historic temple with panoramic views over the city, surrounded by beautiful cherry blossoms.\n",
1555-
"\n",
1556-
"2. **Tokyo**:\n",
1557-
" - **Ueno Park**: One of the most popular spots in Tokyo for hanami (cherry blossom viewing), with numerous trees and a festive atmosphere.\n",
1558-
" - **Shinjuku Gyoen**: A large park offering a tranquil escape with a variety of blooming cherry trees.\n",
1559-
"\n",
1560-
"3. **Osaka**:\n",
1561-
" - **Osaka Castle**: The castle grounds are stunning during cherry blossom season, perfect for both day and night-time viewing with illuminated trees.\n",
1562-
"\n",
1563-
"4. **Hiroshima**:\n",
1564-
" - **Peace Memorial Park**: While visiting for its historical significance, enjoy the cherry blossoms along the Motoyasu River.\n",
1565-
"\n",
1566-
"5. **Nara**:\n",
1567-
" - **Nara Park**: Famous for its free-roaming deer and blooming cherry trees, creating a magical environment.\n",
1568-
"\n",
1569-
"These locations not only offer breathtaking cherry blossom displays but also provide rich cultural and historical experiences. If you have any specific activities or interests, such as arcade visits, feel free to share, and I can provide more tailored recommendations!\n",
1570-
"\n",
1571-
"Assistant: Kyoto is a treasure trove of cultural and historical sites, making it a must-visit during your trip to Japan. Here are the top 5 places to explore in Kyoto:\n",
1572-
"\n",
1573-
"1. **Fushimi Inari Taisha**:\n",
1574-
" - Famous for its thousands of vibrant red torii gates that create a stunning pathway up the sacred Mount Inari. It's an iconic sight that offers both spiritual and photographic opportunities.\n",
1575-
"\n",
1576-
"2. **Kinkaku-ji (Golden Pavilion)**:\n",
1577-
" - A Zen Buddhist temple covered in gold leaf, surrounded by beautiful gardens and a reflective pond. It's a breathtaking example of Japanese architecture and design.\n",
1578-
"\n",
1579-
"3. **Arashiyama Bamboo Grove**:\n",
1580-
" - Walk through the towering bamboo stalks in this serene and otherworldly grove. Nearby, you can also visit the Iwatayama Monkey Park for a fun interaction with wild monkeys.\n",
1581-
"\n",
1582-
"4. **Nijo Castle**:\n",
1583-
" - A UNESCO World Heritage Site, this historic castle is known for its beautiful gardens and ornate interiors. It's a great place to learn about Kyoto's history.\n",
1584-
"\n",
1585-
"5. **Gion District**:\n",
1586-
" - Explore the traditional geisha district with its charming wooden machiya houses. Visit during the evening for a chance to spot geisha or enjoy a traditional tea house experience.\n",
1587-
"\n",
1588-
"These sites offer a mix of cultural, historical, and natural beauty, providing a well-rounded Kyoto experience. If you're interested in specific activities like visiting arcades or bookstores, let me know, and I can provide additional recommendations!\n",
1589-
"Thank you for using the Travel Assistant. Goodbye!\n"
1590-
]
1591-
}
1592-
],
1529+
"outputs": [],
15931530
"source": [
15941531
"import threading\n",
15951532
"\n",

0 commit comments

Comments
 (0)