|
17 | 17 | }, |
18 | 18 | { |
19 | 19 | "cell_type": "code", |
20 | | - "execution_count": 2, |
| 20 | + "execution_count": null, |
21 | 21 | "id": "7a7f9f82", |
22 | 22 | "metadata": {}, |
23 | | - "outputs": [ |
24 | | - { |
25 | | - "name": "stdout", |
26 | | - "output_type": "stream", |
27 | | - "text": [ |
28 | | - "Requirement already satisfied: requests in /opt/homebrew/lib/python3.10/site-packages (2.32.3)\n", |
29 | | - "Requirement already satisfied: tqdm in /opt/homebrew/lib/python3.10/site-packages (4.67.1)\n", |
30 | | - "Requirement already satisfied: charset-normalizer<4,>=2 in /opt/homebrew/lib/python3.10/site-packages (from requests) (3.4.1)\n", |
31 | | - "Requirement already satisfied: idna<4,>=2.5 in /opt/homebrew/lib/python3.10/site-packages (from requests) (3.10)\n", |
32 | | - "Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/homebrew/lib/python3.10/site-packages (from requests) (2.3.0)\n", |
33 | | - "Requirement already satisfied: certifi>=2017.4.17 in /opt/homebrew/lib/python3.10/site-packages (from requests) (2025.1.31)\n", |
34 | | - "\n", |
35 | | - "\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;49m25.1.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.2\u001b[0m\n", |
36 | | - "\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;49m/opt/homebrew/opt/[email protected]/bin/python3.10 -m pip install --upgrade pip\u001b[0m\n", |
37 | | - "\n", |
38 | | - "\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;49m25.1.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.2\u001b[0m\n", |
39 | | - "\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;49m/opt/homebrew/opt/[email protected]/bin/python3.10 -m pip install --upgrade pip\u001b[0m\n", |
40 | | - "Note: you may need to restart the kernel to use updated packages.\n", |
41 | | - "Note: you may need to restart the kernel to use updated packages.\n" |
42 | | - ] |
43 | | - } |
44 | | - ], |
| 23 | + "outputs": [], |
45 | 24 | "source": [ |
46 | 25 | "%pip install requests tqdm elasticsearch" |
47 | 26 | ] |
48 | 27 | }, |
49 | 28 | { |
50 | 29 | "cell_type": "code", |
51 | | - "execution_count": 15, |
| 30 | + "execution_count": null, |
52 | 31 | "id": "f284f828", |
53 | 32 | "metadata": {}, |
54 | 33 | "outputs": [], |
|
72 | 51 | }, |
73 | 52 | { |
74 | 53 | "cell_type": "code", |
75 | | - "execution_count": 4, |
| 54 | + "execution_count": null, |
76 | 55 | "id": "5fdf1b27", |
77 | 56 | "metadata": {}, |
78 | 57 | "outputs": [], |
79 | 58 | "source": [ |
80 | 59 | "# Configuration - Update these values with your credentials\n", |
81 | 60 | "ELASTICSEARCH_HOST = \"https://tralmis-tral-d91b08.es.us-central1.gcp.elastic.cloud:443\"\n", |
82 | 61 | "ELASTICSEARCH_API_KEY = \"<your_elasticsearch_api_key_here>\"\n", |
83 | | - "MISTRAL_API_KEY = \"<your_mistral_api_key_here>\" \n", |
| 62 | + "MISTRAL_API_KEY = \"<your_mistral_api_key_here>\"\n", |
84 | 63 | "\n", |
85 | 64 | "MISTRAL_MODEL = \"mistral-large-latest\" # Mistral model to use\n", |
86 | | - "INFERENCE_ENDPOINT_NAME = (\n", |
87 | | - " \"mistral-embeddings-chat-completion\" # Name for the inference endpoint\n", |
88 | | - ")\n", |
| 65 | + "INFERENCE_ENDPOINT_NAME = \"mistral-embeddings-chat-completion\" # Name for the inference endpoint\n", |
89 | 66 | "\n", |
90 | 67 | "ELASTICSEARCH_HEADERS = {\n", |
91 | 68 | " \"Authorization\": f\"ApiKey {ELASTICSEARCH_API_KEY}\",\n", |
|
95 | 72 | }, |
96 | 73 | { |
97 | 74 | "cell_type": "code", |
98 | | - "execution_count": 16, |
| 75 | + "execution_count": null, |
99 | 76 | "id": "dc1f402c", |
100 | 77 | "metadata": {}, |
101 | 78 | "outputs": [], |
102 | 79 | "source": [ |
103 | 80 | "# Initialize Elasticsearch client\n", |
104 | | - "es_client = Elasticsearch(\n", |
105 | | - " hosts=[ELASTICSEARCH_HOST],\n", |
106 | | - " api_key=ELASTICSEARCH_API_KEY\n", |
107 | | - ")" |
| 81 | + "es_client = Elasticsearch(hosts=[ELASTICSEARCH_HOST], api_key=ELASTICSEARCH_API_KEY)" |
108 | 82 | ] |
109 | 83 | }, |
110 | 84 | { |
|
119 | 93 | }, |
120 | 94 | { |
121 | 95 | "cell_type": "code", |
122 | | - "execution_count": 17, |
| 96 | + "execution_count": null, |
123 | 97 | "id": "bdbdfaef", |
124 | 98 | "metadata": {}, |
125 | | - "outputs": [ |
126 | | - { |
127 | | - "name": "stdout", |
128 | | - "output_type": "stream", |
129 | | - "text": [ |
130 | | - "Creating Mistral inference endpoint: mistral-embeddings-chat-completion at https://ugo-mistral-test-d91b08.es.us-central1.gcp.elastic.cloud:443\n", |
131 | | - "❌ Error creating inference endpoint: BadRequestError(400, 'resource_already_exists_exception', 'Inference endpoint [mistral-embeddings-chat-completion] already exists')\n", |
132 | | - "✅ Inference endpoint already exists, continuing...\n", |
133 | | - "❌ Error creating inference endpoint: BadRequestError(400, 'resource_already_exists_exception', 'Inference endpoint [mistral-embeddings-chat-completion] already exists')\n", |
134 | | - "✅ Inference endpoint already exists, continuing...\n" |
135 | | - ] |
136 | | - } |
137 | | - ], |
| 99 | + "outputs": [], |
138 | 100 | "source": [ |
139 | 101 | "print(\n", |
140 | 102 | " f\"Creating Mistral inference endpoint: {INFERENCE_ENDPOINT_NAME} at {ELASTICSEARCH_HOST}\"\n", |
|
147 | 109 | " inference_id=INFERENCE_ENDPOINT_NAME,\n", |
148 | 110 | " body={\n", |
149 | 111 | " \"service\": \"mistral\",\n", |
150 | | - " \"service_settings\": {\n", |
151 | | - " \"api_key\": MISTRAL_API_KEY,\n", |
152 | | - " \"model\": MISTRAL_MODEL\n", |
153 | | - " }\n", |
154 | | - " }\n", |
| 112 | + " \"service_settings\": {\"api_key\": MISTRAL_API_KEY, \"model\": MISTRAL_MODEL},\n", |
| 113 | + " },\n", |
155 | 114 | " )\n", |
156 | 115 | "\n", |
157 | 116 | " print(\"Inference endpoint created successfully!\")\n", |
|
176 | 135 | }, |
177 | 136 | { |
178 | 137 | "cell_type": "code", |
179 | | - "execution_count": 18, |
| 138 | + "execution_count": null, |
180 | 139 | "id": "f582d78f", |
181 | 140 | "metadata": {}, |
182 | | - "outputs": [ |
183 | | - { |
184 | | - "name": "stdout", |
185 | | - "output_type": "stream", |
186 | | - "text": [ |
187 | | - "✅ Streaming function defined!\n" |
188 | | - ] |
189 | | - } |
190 | | - ], |
| 141 | + "outputs": [], |
191 | 142 | "source": [ |
192 | 143 | "def stream_chat_completion(\n", |
193 | 144 | " host: str, endpoint_name: str, messages: list\n", |
194 | 145 | ") -> Generator[str, None, None]:\n", |
195 | | - "\n", |
196 | 146 | " url = f\"{host}/_inference/chat_completion/{endpoint_name}/_stream\"\n", |
197 | 147 | "\n", |
198 | 148 | " payload = {\"messages\": messages}\n", |
|
256 | 206 | }, |
257 | 207 | { |
258 | 208 | "cell_type": "code", |
259 | | - "execution_count": 27, |
| 209 | + "execution_count": null, |
260 | 210 | "id": "9f5fbf08", |
261 | 211 | "metadata": {}, |
262 | | - "outputs": [ |
263 | | - { |
264 | | - "name": "stdout", |
265 | | - "output_type": "stream", |
266 | | - "text": [ |
267 | | - "User: What SNES games had a character on a skateboard throwing axes?\n", |
268 | | - "Assistant: \n", |
269 | | - "\n", |
270 | | - "The game you're thinking of isThe game you're thinking of is **\"Aero the Acro-Bat\"** (1993) for the SNES.\n", |
271 | | - "\n", |
272 | | - "While Aero primarily **\"Aero the Acro-Bat\"** (1993) for the SNES.\n", |
273 | | - "\n", |
274 | | - "While Aero primarily throws ** throws **boomerangs** (not axes) and rides a **skateboard** in some levels, itâs the closest match to your description. If you meant a different game, let me know!\n", |
275 | | - "\n", |
276 | | - "*(Note: Noboomerangs** (not axes) and rides a **skateboard** in some levels, itâs the closest match to your description. If you meant a different game, let me know!\n", |
277 | | - "\n", |
278 | | - "*(Note: No SNES game features a character throwing axes while skateboardingâaxes are rare in SNES platformers.)* SNES game features a character throwing axes while skateboardingâaxes are rare in SNES platformers.)*" |
279 | | - ] |
280 | | - } |
281 | | - ], |
| 212 | + "outputs": [], |
282 | 213 | "source": [ |
283 | 214 | "user_question = \"What SNES games had a character on a skateboard throwing axes?\"\n", |
284 | 215 | "\n", |
|
326 | 257 | }, |
327 | 258 | { |
328 | 259 | "cell_type": "code", |
329 | | - "execution_count": 19, |
| 260 | + "execution_count": null, |
330 | 261 | "id": "b87d34d3-e64f-49b7-9403-4179e9cbc0e8", |
331 | 262 | "metadata": {}, |
332 | | - "outputs": [ |
333 | | - { |
334 | | - "name": "stdout", |
335 | | - "output_type": "stream", |
336 | | - "text": [ |
337 | | - "❌ Error creating index 'snes-games': BadRequestError(400, 'resource_already_exists_exception', 'index [snes-games/qCGvcq2oQ_WXF_mMRmTreQ] already exists')\n", |
338 | | - "✅ Index 'snes-games' already exists, continuing...\n" |
339 | | - ] |
340 | | - } |
341 | | - ], |
| 263 | + "outputs": [], |
342 | 264 | "source": [ |
343 | 265 | "INDEX_NAME = \"snes-games\"\n", |
344 | 266 | "snes_mapping = {\n", |
|
358 | 280 | "\n", |
359 | 281 | "try:\n", |
360 | 282 | " # Create the index using the Elasticsearch client\n", |
361 | | - " response = es_client.indices.create(\n", |
362 | | - " index=INDEX_NAME,\n", |
363 | | - " body=snes_mapping\n", |
364 | | - " )\n", |
365 | | - " \n", |
| 283 | + " response = es_client.indices.create(index=INDEX_NAME, body=snes_mapping)\n", |
| 284 | + "\n", |
366 | 285 | " print(f\"✅ Index '{INDEX_NAME}' created successfully!\")\n", |
367 | 286 | " print(f\"Response: {json.dumps(response.body, indent=2)}\")\n", |
368 | | - " \n", |
| 287 | + "\n", |
369 | 288 | "except Exception as e:\n", |
370 | 289 | " print(f\"❌ Error creating index '{INDEX_NAME}': {str(e)}\")\n", |
371 | 290 | " # If the index already exists, that's okay\n", |
372 | | - " if \"already exists\" in str(e).lower() or \"resource_already_exists_exception\" in str(e).lower():\n", |
| 291 | + " if (\n", |
| 292 | + " \"already exists\" in str(e).lower()\n", |
| 293 | + " or \"resource_already_exists_exception\" in str(e).lower()\n", |
| 294 | + " ):\n", |
373 | 295 | " print(f\"✅ Index '{INDEX_NAME}' already exists, continuing...\")" |
374 | 296 | ] |
375 | 297 | }, |
|
473 | 395 | }, |
474 | 396 | { |
475 | 397 | "cell_type": "code", |
476 | | - "execution_count": 22, |
| 398 | + "execution_count": null, |
477 | 399 | "id": "f565cb68", |
478 | 400 | "metadata": {}, |
479 | 401 | "outputs": [], |
|
485 | 407 | " }\n", |
486 | 408 | "\n", |
487 | 409 | " try:\n", |
488 | | - " response = es_client.search(\n", |
489 | | - " index=INDEX_NAME,\n", |
490 | | - " body=search_body\n", |
491 | | - " )\n", |
492 | | - " \n", |
| 410 | + " response = es_client.search(index=INDEX_NAME, body=search_body)\n", |
| 411 | + "\n", |
493 | 412 | " return response.body[\"hits\"][\"hits\"]\n", |
494 | 413 | "\n", |
495 | 414 | " except Exception as e:\n", |
|
499 | 418 | }, |
500 | 419 | { |
501 | 420 | "cell_type": "code", |
502 | | - "execution_count": 26, |
| 421 | + "execution_count": null, |
503 | 422 | "id": "e037b346-d274-45d6-a5a1-8c3e3d5df28f", |
504 | 423 | "metadata": {}, |
505 | | - "outputs": [ |
506 | | - { |
507 | | - "name": "stdout", |
508 | | - "output_type": "stream", |
509 | | - "text": [ |
510 | | - "🔍 Searching for: 'What SNES games had a character on a skateboard throwing axes?'\n", |
511 | | - "\n", |
512 | | - "1. Super Adventure Island•Takahashi Meijin no Daibouken Jima - In this Adventure Island entry, Master Higgins wields either his classic stone axe or a boomerang, with fireballs as power-ups. He can super-jump, but no longer runs faster like in the NES. Higgins must collect fruit to survive, and can ride a skateboard to speed through stages. (Score: 17.37)\n", |
513 | | - "\n", |
514 | | - "2. Super Adventure Island II•Takahashi Meijin no Daibouken Jima II - In Adventure Island II, Master Higgins keeps his stone axe and skateboard but also gains the help of four dinosaur companions, each with unique abilities on land, sea, or air. Players collect fruit to stay alive, find eggs for power-ups, and ride dinos to tackle tougher stages with new variety. (Score: 17.12)\n", |
515 | | - "\n", |
516 | | - "3. Frogger - Frogger is a classic arcade game brought to the SNES by Morning Star Multimedia and Majesco Entertainment. Players guide a frog across busy roads and rivers, avoiding obstacles to reach safety. (Score: 11.19)\n", |
517 | | - "\n", |
518 | | - "4. Itadaki Street 2: Neon Sign wa Bara Iro ni - Itadaki Street 2: Neon Sign wa Bara Iro ni is a board game simulation that combines elements of Monopoly and stock trading. Buy properties, collect rent, and outsmart your opponents to become the wealthiest player. (Score: 9.75)\n", |
519 | | - "\n", |
520 | | - "5. Kikuni Masahiko no Jantoushi Dora Ou - Board game (Score: 9.75)\n", |
521 | | - "\n", |
522 | | - "1. Super Adventure Island•Takahashi Meijin no Daibouken Jima - In this Adventure Island entry, Master Higgins wields either his classic stone axe or a boomerang, with fireballs as power-ups. He can super-jump, but no longer runs faster like in the NES. Higgins must collect fruit to survive, and can ride a skateboard to speed through stages. (Score: 17.37)\n", |
523 | | - "\n", |
524 | | - "2. Super Adventure Island II•Takahashi Meijin no Daibouken Jima II - In Adventure Island II, Master Higgins keeps his stone axe and skateboard but also gains the help of four dinosaur companions, each with unique abilities on land, sea, or air. Players collect fruit to stay alive, find eggs for power-ups, and ride dinos to tackle tougher stages with new variety. (Score: 17.12)\n", |
525 | | - "\n", |
526 | | - "3. Frogger - Frogger is a classic arcade game brought to the SNES by Morning Star Multimedia and Majesco Entertainment. Players guide a frog across busy roads and rivers, avoiding obstacles to reach safety. (Score: 11.19)\n", |
527 | | - "\n", |
528 | | - "4. Itadaki Street 2: Neon Sign wa Bara Iro ni - Itadaki Street 2: Neon Sign wa Bara Iro ni is a board game simulation that combines elements of Monopoly and stock trading. Buy properties, collect rent, and outsmart your opponents to become the wealthiest player. (Score: 9.75)\n", |
529 | | - "\n", |
530 | | - "5. Kikuni Masahiko no Jantoushi Dora Ou - Board game (Score: 9.75)\n" |
531 | | - ] |
532 | | - } |
533 | | - ], |
| 424 | + "outputs": [], |
534 | 425 | "source": [ |
535 | 426 | "test_query = \"What SNES games had a character on a skateboard throwing axes?\"\n", |
536 | 427 | "print(f\"🔍 Searching for: '{test_query}'\")\n", |
|
555 | 446 | }, |
556 | 447 | { |
557 | 448 | "cell_type": "code", |
558 | | - "execution_count": 28, |
| 449 | + "execution_count": null, |
559 | 450 | "id": "4dacdad7", |
560 | 451 | "metadata": {}, |
561 | 452 | "outputs": [], |
|
596 | 487 | }, |
597 | 488 | { |
598 | 489 | "cell_type": "code", |
599 | | - "execution_count": 29, |
| 490 | + "execution_count": null, |
600 | 491 | "id": "32a6054b", |
601 | 492 | "metadata": {}, |
602 | | - "outputs": [ |
603 | | - { |
604 | | - "name": "stdout", |
605 | | - "output_type": "stream", |
606 | | - "text": [ |
607 | | - "Based on the provided context, the **Super Adventure Island** series on the SNES features a character (Master Higgins) who rides a **skateboard** and throws **axes** (specifically a on the provided context, the **Super Adventure Island** series on the SNES features a character (Master Higgins) who rides a **skateboard** and throws **axes** (specifically a stone axe or boomerang).\n", |
608 | | - "\n", |
609 | | - "Here are the two relevant games:\n", |
610 | | - "\n", |
611 | | - "1. **Super Adventure Island (1992)** â Master Higgins uses a **stone axe** and can ride a **skateboard** to speed through stages.\n", |
612 | | - "2. **Super Adventure Island II (1995)** â Master Higgins retains his **stone stone axe or boomerang).\n", |
613 | | - "\n", |
614 | | - "Here are the two relevant games:\n", |
615 | | - "\n", |
616 | | - "1. **Super Adventure Island (1992)** â Master Higgins uses a **stone axe** and can ride a **skateboard** to speed through stages.\n", |
617 | | - "2. **Super Adventure Island II (1995)** â Master Higgins retains his **stone axe** and **skateboard**, while also gaining dinosaur companions for additional abilities.\n", |
618 | | - "\n", |
619 | | - "Both games are **platformers** published by **Hudson Soft**. axe** and **skateboard**, while also gaining dinosaur companions for additional abilities.\n", |
620 | | - "\n", |
621 | | - "Both games are **platformers** published by **Hudson Soft**." |
622 | | - ] |
623 | | - }, |
624 | | - { |
625 | | - "data": { |
626 | | - "text/plain": [ |
627 | | - "'Based on the provided context, the **Super Adventure Island** series on the SNES features a character (Master Higgins) who rides a **skateboard** and throws **axes** (specifically a stone axe or boomerang).\\n\\nHere are the two relevant games:\\n\\n1. **Super Adventure Island (1992)** â\\x80\\x93 Master Higgins uses a **stone axe** and can ride a **skateboard** to speed through stages.\\n2. **Super Adventure Island II (1995)** â\\x80\\x93 Master Higgins retains his **stone axe** and **skateboard**, while also gaining dinosaur companions for additional abilities.\\n\\nBoth games are **platformers** published by **Hudson Soft**.'" |
628 | | - ] |
629 | | - }, |
630 | | - "execution_count": 29, |
631 | | - "metadata": {}, |
632 | | - "output_type": "execute_result" |
633 | | - } |
634 | | - ], |
| 493 | + "outputs": [], |
635 | 494 | "source": [ |
636 | 495 | "test_question = \"What SNES games had a character on a skateboard throwing axes?\"\n", |
637 | 496 | "rag_chat(test_question)" |
|
0 commit comments