daniel.diaz commited on
Commit
1966e2b
·
1 Parent(s): a735235

changes for 4 mini OPenAPI model

Browse files
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
.ipynb_checkpoints/rag_jujutsu_poc_joblib-checkpoint.ipynb ADDED
@@ -0,0 +1,479 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "ebeba428",
6
+ "metadata": {},
7
+ "source": [
8
+ "# ✅ RAG JuJutsu PoC (Notebook with Joblib, FAISS, ChatGPT API)"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": null,
14
+ "id": "8bdfd3c8",
15
+ "metadata": {},
16
+ "outputs": [
17
+ {
18
+ "name": "stdout",
19
+ "output_type": "stream",
20
+ "text": [
21
+ "Requirement already satisfied: ipywidgets==7.7.2 in /opt/anaconda3/lib/python3.11/site-packages (7.7.2)\n",
22
+ "Requirement already satisfied: ipykernel>=4.5.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (6.28.0)\n",
23
+ "Requirement already satisfied: ipython-genutils~=0.2.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (0.2.0)\n",
24
+ "Requirement already satisfied: traitlets>=4.3.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (5.7.1)\n",
25
+ "Requirement already satisfied: widgetsnbextension~=3.6.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (3.6.10)\n",
26
+ "Requirement already satisfied: ipython>=4.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (8.20.0)\n",
27
+ "Requirement already satisfied: jupyterlab-widgets<3,>=1.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (1.1.11)\n",
28
+ "Requirement already satisfied: appnope in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (0.1.2)\n",
29
+ "Requirement already satisfied: comm>=0.1.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (0.1.2)\n",
30
+ "Requirement already satisfied: debugpy>=1.6.5 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (1.6.7)\n",
31
+ "Requirement already satisfied: jupyter-client>=6.1.12 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (8.6.0)\n",
32
+ "Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (5.5.0)\n",
33
+ "Requirement already satisfied: matplotlib-inline>=0.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (0.1.6)\n",
34
+ "Requirement already satisfied: nest-asyncio in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (1.6.0)\n",
35
+ "Requirement already satisfied: packaging in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (23.2)\n",
36
+ "Requirement already satisfied: psutil in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (5.9.0)\n",
37
+ "Requirement already satisfied: pyzmq>=24 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (25.1.2)\n",
38
+ "Requirement already satisfied: tornado>=6.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (6.3.3)\n",
39
+ "Requirement already satisfied: decorator in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (5.1.1)\n",
40
+ "Requirement already satisfied: jedi>=0.16 in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (0.18.1)\n",
41
+ "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (3.0.43)\n",
42
+ "Requirement already satisfied: pygments>=2.4.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (2.15.1)\n",
43
+ "Requirement already satisfied: stack-data in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (0.2.0)\n",
44
+ "Requirement already satisfied: pexpect>4.3 in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (4.8.0)\n",
45
+ "Requirement already satisfied: notebook>=4.4.1 in /opt/anaconda3/lib/python3.11/site-packages (from widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (7.3.2)\n",
46
+ "Requirement already satisfied: parso<0.9.0,>=0.8.0 in /opt/anaconda3/lib/python3.11/site-packages (from jedi>=0.16->ipython>=4.0.0->ipywidgets==7.7.2) (0.8.3)\n",
47
+ "Requirement already satisfied: python-dateutil>=2.8.2 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-client>=6.1.12->ipykernel>=4.5.1->ipywidgets==7.7.2) (2.9.0.post0)\n",
48
+ "Requirement already satisfied: platformdirs>=2.5 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-core!=5.0.*,>=4.12->ipykernel>=4.5.1->ipywidgets==7.7.2) (3.10.0)\n",
49
+ "Requirement already satisfied: jupyter-server<3,>=2.4.0 in /opt/anaconda3/lib/python3.11/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.10.0)\n",
50
+ "Requirement already satisfied: jupyterlab-server<3,>=2.27.1 in /opt/anaconda3/lib/python3.11/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.27.3)\n",
51
+ "Requirement already satisfied: jupyterlab<4.4,>=4.3.4 in /opt/anaconda3/lib/python3.11/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.3.4)\n",
52
+ "Requirement already satisfied: notebook-shim<0.3,>=0.2 in /opt/anaconda3/lib/python3.11/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.2.3)\n",
53
+ "Requirement already satisfied: ptyprocess>=0.5 in /opt/anaconda3/lib/python3.11/site-packages (from pexpect>4.3->ipython>=4.0.0->ipywidgets==7.7.2) (0.7.0)\n",
54
+ "Requirement already satisfied: wcwidth in /opt/anaconda3/lib/python3.11/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython>=4.0.0->ipywidgets==7.7.2) (0.2.5)\n",
55
+ "Requirement already satisfied: executing in /opt/anaconda3/lib/python3.11/site-packages (from stack-data->ipython>=4.0.0->ipywidgets==7.7.2) (0.8.3)\n",
56
+ "Requirement already satisfied: asttokens in /opt/anaconda3/lib/python3.11/site-packages (from stack-data->ipython>=4.0.0->ipywidgets==7.7.2) (2.0.5)\n",
57
+ "Requirement already satisfied: pure-eval in /opt/anaconda3/lib/python3.11/site-packages (from stack-data->ipython>=4.0.0->ipywidgets==7.7.2) (0.2.2)\n",
58
+ "Requirement already satisfied: anyio>=3.1.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.2.0)\n",
59
+ "Requirement already satisfied: argon2-cffi in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (21.3.0)\n",
60
+ "Requirement already satisfied: jinja2 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (3.1.3)\n",
61
+ "Requirement already satisfied: jupyter-events>=0.6.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.8.0)\n",
62
+ "Requirement already satisfied: jupyter-server-terminals in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.4.4)\n",
63
+ "Requirement already satisfied: nbconvert>=6.4.4 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (7.16.3)\n",
64
+ "Requirement already satisfied: nbformat>=5.3.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (5.9.2)\n",
65
+ "Requirement already satisfied: overrides in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (7.4.0)\n",
66
+ "Requirement already satisfied: prometheus-client in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.14.1)\n",
67
+ "Requirement already satisfied: send2trash>=1.8.2 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.8.2)\n",
68
+ "Requirement already satisfied: terminado>=0.8.3 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.17.1)\n",
69
+ "Requirement already satisfied: websocket-client in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.58.0)\n",
70
+ "Requirement already satisfied: async-lru>=1.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.4)\n",
71
+ "Requirement already satisfied: httpx>=0.25.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.26.0)\n",
72
+ "Requirement already satisfied: jupyter-lsp>=2.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.2.0)\n",
73
+ "Requirement already satisfied: setuptools>=40.8.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (68.2.2)\n",
74
+ "Requirement already satisfied: babel>=2.10 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.11.0)\n",
75
+ "Requirement already satisfied: json5>=0.9.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.9.6)\n",
76
+ "Requirement already satisfied: jsonschema>=4.18.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.19.2)\n",
77
+ "Requirement already satisfied: requests>=2.31 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.32.3)\n",
78
+ "Requirement already satisfied: six>=1.5 in /opt/anaconda3/lib/python3.11/site-packages (from python-dateutil>=2.8.2->jupyter-client>=6.1.12->ipykernel>=4.5.1->ipywidgets==7.7.2) (1.17.0)\n",
79
+ "Requirement already satisfied: idna>=2.8 in /opt/anaconda3/lib/python3.11/site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (3.4)\n",
80
+ "Requirement already satisfied: sniffio>=1.1 in /opt/anaconda3/lib/python3.11/site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.3.0)\n",
81
+ "Requirement already satisfied: pytz>=2015.7 in /opt/anaconda3/lib/python3.11/site-packages (from babel>=2.10->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2025.2)\n",
82
+ "Requirement already satisfied: certifi in /opt/anaconda3/lib/python3.11/site-packages (from httpx>=0.25.0->jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2025.1.31)\n",
83
+ "Requirement already satisfied: httpcore==1.* in /opt/anaconda3/lib/python3.11/site-packages (from httpx>=0.25.0->jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.0.2)\n",
84
+ "Requirement already satisfied: h11<0.15,>=0.13 in /opt/anaconda3/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.14.0)\n",
85
+ "Requirement already satisfied: MarkupSafe>=2.0 in /opt/anaconda3/lib/python3.11/site-packages (from jinja2->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.1.3)\n",
86
+ "Requirement already satisfied: attrs>=22.2.0 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (23.1.0)\n",
87
+ "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2023.7.1)\n",
88
+ "Requirement already satisfied: referencing>=0.28.4 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.30.2)\n",
89
+ "Requirement already satisfied: rpds-py>=0.7.1 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.10.6)\n",
90
+ "Requirement already satisfied: python-json-logger>=2.0.4 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.7)\n",
91
+ "Requirement already satisfied: pyyaml>=5.3 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (6.0.1)\n",
92
+ "Requirement already satisfied: rfc3339-validator in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.1.4)\n",
93
+ "Requirement already satisfied: rfc3986-validator>=0.1.1 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.1.1)\n",
94
+ "Requirement already satisfied: beautifulsoup4 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.12.2)\n",
95
+ "Requirement already satisfied: bleach!=5.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.1.0)\n",
96
+ "Requirement already satisfied: defusedxml in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.7.1)\n",
97
+ "Requirement already satisfied: jupyterlab-pygments in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.1.2)\n",
98
+ "Requirement already satisfied: mistune<4,>=2.0.3 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.4)\n",
99
+ "Requirement already satisfied: nbclient>=0.5.0 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.8.0)\n",
100
+ "Requirement already satisfied: pandocfilters>=1.4.1 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.5.0)\n",
101
+ "Requirement already satisfied: tinycss2 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.2.1)\n",
102
+ "Requirement already satisfied: fastjsonschema in /opt/anaconda3/lib/python3.11/site-packages (from nbformat>=5.3.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.16.2)\n",
103
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /opt/anaconda3/lib/python3.11/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.4)\n",
104
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/anaconda3/lib/python3.11/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.7)\n",
105
+ "Requirement already satisfied: argon2-cffi-bindings in /opt/anaconda3/lib/python3.11/site-packages (from argon2-cffi->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (21.2.0)\n",
106
+ "Requirement already satisfied: webencodings in /opt/anaconda3/lib/python3.11/site-packages (from bleach!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.5.1)\n",
107
+ "Requirement already satisfied: fqdn in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.5.1)\n",
108
+ "Requirement already satisfied: isoduration in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (20.11.0)\n",
109
+ "Requirement already satisfied: jsonpointer>1.13 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.1)\n",
110
+ "Requirement already satisfied: uri-template in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.3.0)\n",
111
+ "Requirement already satisfied: webcolors>=1.11 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (24.11.1)\n",
112
+ "Requirement already satisfied: cffi>=1.0.1 in /opt/anaconda3/lib/python3.11/site-packages (from argon2-cffi-bindings->argon2-cffi->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.16.0)\n",
113
+ "Requirement already satisfied: soupsieve>1.2 in /opt/anaconda3/lib/python3.11/site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.5)\n",
114
+ "Requirement already satisfied: pycparser in /opt/anaconda3/lib/python3.11/site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.21)\n",
115
+ "Requirement already satisfied: arrow>=0.15.0 in /opt/anaconda3/lib/python3.11/site-packages (from isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.2.3)\n",
116
+ "usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]\n",
117
+ " [--paths] [--json] [--debug]\n",
118
+ " [subcommand]\n",
119
+ "\n",
120
+ "Jupyter: Interactive Computing\n",
121
+ "\n",
122
+ "positional arguments:\n",
123
+ " subcommand the subcommand to launch\n",
124
+ "\n",
125
+ "options:\n",
126
+ " -h, --help show this help message and exit\n",
127
+ " --version show the versions of core jupyter packages and exit\n",
128
+ " --config-dir show Jupyter config dir\n",
129
+ " --data-dir show Jupyter data dir\n",
130
+ " --runtime-dir show Jupyter runtime dir\n",
131
+ " --paths show all Jupyter paths. Add --json for machine-readable\n",
132
+ " format.\n",
133
+ " --json output paths as machine-readable json\n",
134
+ " --debug output debug information about paths\n",
135
+ "\n",
136
+ "Available subcommands: console dejavu events execute kernel kernelspec lab\n",
137
+ "labextension labhub migrate nbconvert notebook qtconsole run server\n",
138
+ "troubleshoot trust\n",
139
+ "\n",
140
+ "Jupyter command `jupyter-nbextension` not found.\n",
141
+ "\u001b[32m[I 2025-06-14 22:49:12.578 ServerApp]\u001b[m Package notebook took 0.0000s to import\n",
142
+ "\u001b[32m[I 2025-06-14 22:49:12.740 ServerApp]\u001b[m Package aext_assistant took 0.1621s to import\n",
143
+ "\u001b[32m[I 2025-06-14 22:49:12.741 ServerApp]\u001b[m Package aext_core took 0.0011s to import\n",
144
+ "\u001b[33m[W 2025-06-14 22:49:12.748 ServerApp]\u001b[m aext_panels | error adding extension (enabled: True): The module 'aext_panels' could not be found (cannot import name 'AuthConfig' from 'anaconda_cloud_auth.client' (/opt/anaconda3/lib/python3.11/site-packages/anaconda_cloud_auth/client.py)). Are you sure the extension is installed?\n",
145
+ " Traceback (most recent call last):\n",
146
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/manager.py\", line 321, in add_extension\n",
147
+ " extpkg = ExtensionPackage(name=extension_name, enabled=enabled)\n",
148
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
149
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/manager.py\", line 185, in __init__\n",
150
+ " self._load_metadata()\n",
151
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/manager.py\", line 200, in _load_metadata\n",
152
+ " raise ExtensionModuleNotFound(msg) from None\n",
153
+ " jupyter_server.extension.utils.ExtensionModuleNotFound: The module 'aext_panels' could not be found (cannot import name 'AuthConfig' from 'anaconda_cloud_auth.client' (/opt/anaconda3/lib/python3.11/site-packages/anaconda_cloud_auth/client.py)). Are you sure the extension is installed?\n",
154
+ "\u001b[32m[I 2025-06-14 22:49:12.750 ServerApp]\u001b[m Package aext_share_notebook took 0.0009s to import\n",
155
+ "\u001b[32m[I 2025-06-14 22:49:12.757 ServerApp]\u001b[m Package jupyter_lsp took 0.0074s to import\n",
156
+ "\u001b[33m[W 2025-06-14 22:49:12.757 ServerApp]\u001b[m A `_jupyter_server_extension_points` function was not found in jupyter_lsp. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.\n",
157
+ "\u001b[32m[I 2025-06-14 22:49:12.761 ServerApp]\u001b[m Package jupyter_server_terminals took 0.0035s to import\n",
158
+ "\u001b[32m[I 2025-06-14 22:49:12.761 ServerApp]\u001b[m Package jupyterlab took 0.0000s to import\n",
159
+ "\u001b[32m[I 2025-06-14 22:49:13.042 ServerApp]\u001b[m Package notebook_shim took 0.0000s to import\n",
160
+ "\u001b[33m[W 2025-06-14 22:49:13.042 ServerApp]\u001b[m A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.\n",
161
+ "\u001b[32m[I 2025-06-14 22:49:13.470 ServerApp]\u001b[m Package panel.io.jupyter_server_extension took 0.4273s to import\n",
162
+ "\u001b[32m[I 2025-06-14 22:49:13.471 ServerApp]\u001b[m aext_assistant | extension was successfully linked.\n",
163
+ "\u001b[32m[I 2025-06-14 22:49:13.471 ServerApp]\u001b[m aext_core | extension was successfully linked.\n",
164
+ "\u001b[32m[I 2025-06-14 22:49:13.471 ServerApp]\u001b[m aext_share_notebook | extension was successfully linked.\n",
165
+ "\u001b[32m[I 2025-06-14 22:49:13.471 ServerApp]\u001b[m jupyter_lsp | extension was successfully linked.\n",
166
+ "\u001b[32m[I 2025-06-14 22:49:13.473 ServerApp]\u001b[m jupyter_server_terminals | extension was successfully linked.\n",
167
+ "\u001b[32m[I 2025-06-14 22:49:13.474 ServerApp]\u001b[m jupyterlab | extension was successfully linked.\n",
168
+ "\u001b[32m[I 2025-06-14 22:49:13.475 ServerApp]\u001b[m notebook | extension was successfully linked.\n",
169
+ "\u001b[32m[I 2025-06-14 22:49:13.564 ServerApp]\u001b[m notebook_shim | extension was successfully linked.\n",
170
+ "\u001b[32m[I 2025-06-14 22:49:13.564 ServerApp]\u001b[m panel.io.jupyter_server_extension | extension was successfully linked.\n",
171
+ "\u001b[32m[I 2025-06-14 22:49:13.584 ServerApp]\u001b[m notebook_shim | extension was successfully loaded.\n",
172
+ "\u001b[32m[I 2025-06-14 22:49:13.585 ServerApp]\u001b[m Registered aext_assistant server extension\n",
173
+ "\u001b[32m[I 2025-06-14 22:49:13.585 ServerApp]\u001b[m aext_assistant | extension was successfully loaded.\n",
174
+ "\u001b[32m[I 2025-06-14 22:49:13.585 ServerApp]\u001b[m Registered aext_core server extension\n",
175
+ "\u001b[32m[I 2025-06-14 22:49:13.585 ServerApp]\u001b[m aext_core | extension was successfully loaded.\n",
176
+ "\u001b[32m[I 2025-06-14 22:49:13.585 ServerApp]\u001b[m Registered aext_share_notebook_server server extension\n",
177
+ "\u001b[32m[I 2025-06-14 22:49:13.585 ServerApp]\u001b[m aext_share_notebook | extension was successfully loaded.\n",
178
+ "\u001b[32m[I 2025-06-14 22:49:13.586 ServerApp]\u001b[m jupyter_lsp | extension was successfully loaded.\n",
179
+ "\u001b[32m[I 2025-06-14 22:49:13.586 ServerApp]\u001b[m jupyter_server_terminals | extension was successfully loaded.\n",
180
+ "\u001b[32m[I 2025-06-14 22:49:13.588 LabApp]\u001b[m JupyterLab extension loaded from /opt/anaconda3/lib/python3.11/site-packages/jupyterlab\n",
181
+ "\u001b[32m[I 2025-06-14 22:49:13.588 LabApp]\u001b[m JupyterLab application directory is /opt/anaconda3/share/jupyter/lab\n",
182
+ "\u001b[32m[I 2025-06-14 22:49:13.589 LabApp]\u001b[m Extension Manager is 'pypi'.\n",
183
+ "\u001b[32m[I 2025-06-14 22:49:13.606 ServerApp]\u001b[m jupyterlab | extension was successfully loaded.\n",
184
+ "\u001b[32m[I 2025-06-14 22:49:13.608 ServerApp]\u001b[m notebook | extension was successfully loaded.\n",
185
+ "\u001b[32m[I 2025-06-14 22:49:13.608 ServerApp]\u001b[m panel.io.jupyter_server_extension | extension was successfully loaded.\n",
186
+ "\u001b[32m[I 2025-06-14 22:49:13.609 ServerApp]\u001b[m The port 8888 is already in use, trying another port.\n",
187
+ "\u001b[32m[I 2025-06-14 22:49:13.609 ServerApp]\u001b[m The port 8889 is already in use, trying another port.\n",
188
+ "\u001b[32m[I 2025-06-14 22:49:13.609 ServerApp]\u001b[m The port 8890 is already in use, trying another port.\n",
189
+ "\u001b[32m[I 2025-06-14 22:49:13.610 ServerApp]\u001b[m Serving notebooks from local directory: /Users/ddiaz/Desktop/Proyectos_ImageMarker/POC-JuJitsu\n",
190
+ "\u001b[32m[I 2025-06-14 22:49:13.610 ServerApp]\u001b[m Jupyter Server 2.10.0 is running at:\n",
191
+ "\u001b[32m[I 2025-06-14 22:49:13.610 ServerApp]\u001b[m http://localhost:8891/tree?token=da5dcdce5100318c25020e1cce57e2b157f8243ee0051999\n",
192
+ "\u001b[32m[I 2025-06-14 22:49:13.610 ServerApp]\u001b[m http://127.0.0.1:8891/tree?token=da5dcdce5100318c25020e1cce57e2b157f8243ee0051999\n",
193
+ "\u001b[32m[I 2025-06-14 22:49:13.610 ServerApp]\u001b[m Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).\n",
194
+ "\u001b[35m[C 2025-06-14 22:49:13.611 ServerApp]\u001b[m \n",
195
+ " \n",
196
+ " To access the server, open this file in a browser:\n",
197
+ " file:///Users/ddiaz/Library/Jupyter/runtime/jpserver-72351-open.html\n",
198
+ " Or copy and paste one of these URLs:\n",
199
+ " http://localhost:8891/tree?token=da5dcdce5100318c25020e1cce57e2b157f8243ee0051999\n",
200
+ " http://127.0.0.1:8891/tree?token=da5dcdce5100318c25020e1cce57e2b157f8243ee0051999\n",
201
+ "\u001b[32m[I 2025-06-14 22:49:13.912 ServerApp]\u001b[m Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server\n",
202
+ "0.00s - Debugger warning: It seems that frozen modules are being used, which may\n",
203
+ "0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off\n",
204
+ "0.00s - to python to disable frozen modules.\n",
205
+ "0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.\n",
206
+ "\u001b[33m[W 2025-06-14 22:49:15.430 ServerApp]\u001b[m wrote error: 'Forbidden'\n",
207
+ " Traceback (most recent call last):\n",
208
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
209
+ " result = await result\n",
210
+ " ^^^^^^^^^^^^\n",
211
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/aext_assistant_server/handlers.py\", line 117, in get\n",
212
+ " raise HTTPError(403, reason=\"missing nucleus_token\")\n",
213
+ " tornado.web.HTTPError: HTTP 403: missing nucleus_token\n",
214
+ "\u001b[33m[W 2025-06-14 22:49:15.432 ServerApp]\u001b[m 403 GET /aext_assistant_server/nucleus_token?1749962955366 (e1bb6698e462478ab1b1bdda87374748@::1) 2.68ms referer=http://localhost:8891/tree\n",
215
+ "\u001b[33m[W 2025-06-14 22:49:31.915 ServerApp]\u001b[m wrote error: 'Forbidden'\n",
216
+ " Traceback (most recent call last):\n",
217
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
218
+ " result = await result\n",
219
+ " ^^^^^^^^^^^^\n",
220
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/aext_assistant_server/handlers.py\", line 117, in get\n",
221
+ " raise HTTPError(403, reason=\"missing nucleus_token\")\n",
222
+ " tornado.web.HTTPError: HTTP 403: missing nucleus_token\n",
223
+ "\u001b[33m[W 2025-06-14 22:49:31.915 ServerApp]\u001b[m 403 GET /aext_assistant_server/nucleus_token?1749962971861 (e1bb6698e462478ab1b1bdda87374748@::1) 1.29ms referer=http://localhost:8891/tree\n"
224
+ ]
225
+ }
226
+ ],
227
+ "source": [
228
+ "\n",
229
+ "!pip install --quiet openai langchain faiss-cpu PyPDF2 sentence-transformers joblib\n",
230
+ "!pip install ipywidgets==7.7.2\n",
231
+ "!jupyter nbextension enable --py widgetsnbextension\n",
232
+ "!jupyter notebook\n"
233
+ ]
234
+ },
235
+ {
236
+ "cell_type": "code",
237
+ "execution_count": 1,
238
+ "id": "49ee7721",
239
+ "metadata": {},
240
+ "outputs": [
241
+ {
242
+ "name": "stdout",
243
+ "output_type": "stream",
244
+ "text": [
245
+ "Loaded 329 chunks\n"
246
+ ]
247
+ }
248
+ ],
249
+ "source": [
250
+ "\n",
251
+ "from PyPDF2 import PdfReader\n",
252
+ "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
253
+ "\n",
254
+ "def load_pdf_chunks(pdf_path):\n",
255
+ " reader = PdfReader(pdf_path)\n",
256
+ " raw_text = \"\"\n",
257
+ " for page in reader.pages:\n",
258
+ " raw_text += page.extract_text() + \"\\n\"\n",
259
+ "\n",
260
+ " splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)\n",
261
+ " return splitter.split_text(raw_text)\n",
262
+ "\n",
263
+ "chunks = load_pdf_chunks(\"JuJutsu-Contexto-Significado-Conexiones-Historia.pdf\")\n",
264
+ "print(f\"Loaded {len(chunks)} chunks\")\n"
265
+ ]
266
+ },
267
+ {
268
+ "cell_type": "code",
269
+ "execution_count": 3,
270
+ "id": "371c637e",
271
+ "metadata": {},
272
+ "outputs": [
273
+ {
274
+ "name": "stdout",
275
+ "output_type": "stream",
276
+ "text": [
277
+ "Model, chunks, and index serialized to rag_model.joblib\n"
278
+ ]
279
+ }
280
+ ],
281
+ "source": [
282
+ "\n",
283
+ "from sentence_transformers import SentenceTransformer\n",
284
+ "import faiss\n",
285
+ "import numpy as np\n",
286
+ "import joblib\n",
287
+ "\n",
288
+ "model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')\n",
289
+ "embeddings = model.encode(chunks)\n",
290
+ "\n",
291
+ "index = faiss.IndexFlatL2(embeddings.shape[1])\n",
292
+ "index.add(np.array(embeddings))\n",
293
+ "\n",
294
+ "joblib.dump((model, chunks, index), \"rag_model.joblib\")\n",
295
+ "print(\"Model, chunks, and index serialized to rag_model.joblib\")\n"
296
+ ]
297
+ },
298
+ {
299
+ "cell_type": "code",
300
+ "execution_count": 5,
301
+ "id": "28ce4963",
302
+ "metadata": {},
303
+ "outputs": [
304
+ {
305
+ "name": "stdout",
306
+ "output_type": "stream",
307
+ "text": [
308
+ "Model, chunks, and index loaded from rag_model.joblib\n"
309
+ ]
310
+ }
311
+ ],
312
+ "source": [
313
+ "\n",
314
+ "import joblib\n",
315
+ "\n",
316
+ "model, chunks, index = joblib.load(\"rag_model.joblib\")\n",
317
+ "print(\"Model, chunks, and index loaded from rag_model.joblib\")\n"
318
+ ]
319
+ },
320
+ {
321
+ "cell_type": "code",
322
+ "execution_count": 7,
323
+ "id": "51a89e77",
324
+ "metadata": {},
325
+ "outputs": [],
326
+ "source": [
327
+ "\n",
328
+ "def search(query, k=3):\n",
329
+ " query_vec = model.encode([query])\n",
330
+ " scores, indices = index.search(np.array(query_vec), k)\n",
331
+ " return [chunks[i] for i in indices[0]]\n"
332
+ ]
333
+ },
334
+ {
335
+ "cell_type": "code",
336
+ "execution_count": 23,
337
+ "id": "34315775",
338
+ "metadata": {},
339
+ "outputs": [],
340
+ "source": [
341
+ "\n",
342
+ "import os\n",
343
+ "\n",
344
+ "import openai\n",
345
+ "from openai import OpenAI\n",
346
+ "\n",
347
+ "os.environ[\"OPENAI_API_KEY\"] = \"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\"\n",
348
+ "\n",
349
+ "\n",
350
+ "client = OpenAI() # Uses env variable OPENAI_API_KEY\n",
351
+ "\n",
352
+ "def chat_no_rag(question):\n",
353
+ " response = client.chat.completions.create(\n",
354
+ " model=\"gpt-4o\",\n",
355
+ " messages=[\n",
356
+ " {\"role\": \"user\", \"content\": question}\n",
357
+ " ],\n",
358
+ " temperature=0.5,\n",
359
+ " max_tokens=200, # 👈 Limit output to ~150-200 words\n",
360
+ "\n",
361
+ " )\n",
362
+ " return response.choices[0].message.content\n",
363
+ "\n",
364
+ "def chat_with_rag(question, retrieved_chunks):\n",
365
+ " context = \"\\n\".join(retrieved_chunks)\n",
366
+ " prompt = f\"Usa el siguiente contexto para responder la pregunta:\\n\\n{context}\\n\\nPregunta: {question}\"\n",
367
+ "\n",
368
+ " response = client.chat.completions.create(\n",
369
+ " model=\"gpt-4o\",\n",
370
+ " messages=[\n",
371
+ " {\"role\": \"user\", \"content\": prompt}\n",
372
+ " ],\n",
373
+ " temperature=0.3,\n",
374
+ " max_tokens=200, # 👈 Limit output to ~150-200 words\n",
375
+ " )\n",
376
+ " return response.choices[0].message.content\n",
377
+ "\n",
378
+ "\n",
379
+ "def chat_with_rag_enhanced(question, retrieved_chunks):\n",
380
+ " context = \"\\n\".join(retrieved_chunks)\n",
381
+ " prompt = (\n",
382
+ " \"Eres un experto en historia marcial. \"\n",
383
+ " \"Usa el siguiente contexto histórico para responder con precisión y detalle.\\n\\n\"\n",
384
+ " f\"Contexto:\\n{context}\\n\\n\"\n",
385
+ " f\"Pregunta: {question}\\nRespuesta:\"\n",
386
+ " )\n",
387
+ "\n",
388
+ " response = client.chat.completions.create(\n",
389
+ " model=\"gpt-4o\",\n",
390
+ " messages=[\n",
391
+ " {\"role\": \"user\", \"content\": prompt}\n",
392
+ " ],\n",
393
+ " temperature=0.2,\n",
394
+ " max_tokens=200, # 👈 Limit output to ~150-200 words\n",
395
+ " )\n",
396
+ " return response.choices[0].message.content\n",
397
+ "\n",
398
+ "\n",
399
+ "\n",
400
+ "\n"
401
+ ]
402
+ },
403
+ {
404
+ "cell_type": "code",
405
+ "execution_count": 25,
406
+ "id": "900dfdfa",
407
+ "metadata": {},
408
+ "outputs": [
409
+ {
410
+ "name": "stdout",
411
+ "output_type": "stream",
412
+ "text": [
413
+ "🔹 Sin RAG:\n"
414
+ ]
415
+ },
416
+ {
417
+ "ename": "RateLimitError",
418
+ "evalue": "Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}",
419
+ "output_type": "error",
420
+ "traceback": [
421
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
422
+ "\u001b[0;31mRateLimitError\u001b[0m Traceback (most recent call last)",
423
+ "Cell \u001b[0;32mIn[25], line 6\u001b[0m\n\u001b[1;32m 3\u001b[0m retrieved \u001b[38;5;241m=\u001b[39m search(query)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m🔹 Sin RAG:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(chat_no_rag(query))\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m🔹 Con RAG:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(chat_with_rag(query, retrieved))\n",
424
+ "Cell \u001b[0;32mIn[23], line 12\u001b[0m, in \u001b[0;36mchat_no_rag\u001b[0;34m(question)\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mchat_no_rag\u001b[39m(question):\n\u001b[0;32m---> 12\u001b[0m response \u001b[38;5;241m=\u001b[39m client\u001b[38;5;241m.\u001b[39mchat\u001b[38;5;241m.\u001b[39mcompletions\u001b[38;5;241m.\u001b[39mcreate(\n\u001b[1;32m 13\u001b[0m model\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgpt-4o\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 14\u001b[0m messages\u001b[38;5;241m=\u001b[39m[\n\u001b[1;32m 15\u001b[0m {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mrole\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muser\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcontent\u001b[39m\u001b[38;5;124m\"\u001b[39m: question}\n\u001b[1;32m 16\u001b[0m ],\n\u001b[1;32m 17\u001b[0m temperature\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.5\u001b[39m,\n\u001b[1;32m 18\u001b[0m )\n\u001b[1;32m 19\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m response\u001b[38;5;241m.\u001b[39mchoices[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mmessage\u001b[38;5;241m.\u001b[39mcontent\n",
425
+ "File \u001b[0;32m/opt/anaconda3/lib/python3.11/site-packages/openai/_utils/_utils.py:287\u001b[0m, in \u001b[0;36mrequired_args.<locals>.inner.<locals>.wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 285\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMissing required argument: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mquote(missing[\u001b[38;5;241m0\u001b[39m])\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 286\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(msg)\n\u001b[0;32m--> 287\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
426
+ "File \u001b[0;32m/opt/anaconda3/lib/python3.11/site-packages/openai/resources/chat/completions/completions.py:925\u001b[0m, in \u001b[0;36mCompletions.create\u001b[0;34m(self, messages, model, audio, frequency_penalty, function_call, functions, logit_bias, logprobs, max_completion_tokens, max_tokens, metadata, modalities, n, parallel_tool_calls, prediction, presence_penalty, reasoning_effort, response_format, seed, service_tier, stop, store, stream, stream_options, temperature, tool_choice, tools, top_logprobs, top_p, user, web_search_options, extra_headers, extra_query, extra_body, timeout)\u001b[0m\n\u001b[1;32m 882\u001b[0m \u001b[38;5;129m@required_args\u001b[39m([\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmessages\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m\"\u001b[39m], [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmessages\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstream\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[1;32m 883\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcreate\u001b[39m(\n\u001b[1;32m 884\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 922\u001b[0m timeout: \u001b[38;5;28mfloat\u001b[39m \u001b[38;5;241m|\u001b[39m httpx\u001b[38;5;241m.\u001b[39mTimeout \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m|\u001b[39m NotGiven \u001b[38;5;241m=\u001b[39m NOT_GIVEN,\n\u001b[1;32m 923\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m ChatCompletion \u001b[38;5;241m|\u001b[39m Stream[ChatCompletionChunk]:\n\u001b[1;32m 924\u001b[0m validate_response_format(response_format)\n\u001b[0;32m--> 925\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_post(\n\u001b[1;32m 926\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m/chat/completions\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 927\u001b[0m body\u001b[38;5;241m=\u001b[39mmaybe_transform(\n\u001b[1;32m 928\u001b[0m {\n\u001b[1;32m 929\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmessages\u001b[39m\u001b[38;5;124m\"\u001b[39m: messages,\n\u001b[1;32m 930\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m\"\u001b[39m: model,\n\u001b[1;32m 931\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124maudio\u001b[39m\u001b[38;5;124m\"\u001b[39m: audio,\n\u001b[1;32m 932\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfrequency_penalty\u001b[39m\u001b[38;5;124m\"\u001b[39m: frequency_penalty,\n\u001b[1;32m 933\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfunction_call\u001b[39m\u001b[38;5;124m\"\u001b[39m: function_call,\n\u001b[1;32m 934\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfunctions\u001b[39m\u001b[38;5;124m\"\u001b[39m: functions,\n\u001b[1;32m 935\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlogit_bias\u001b[39m\u001b[38;5;124m\"\u001b[39m: logit_bias,\n\u001b[1;32m 936\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlogprobs\u001b[39m\u001b[38;5;124m\"\u001b[39m: logprobs,\n\u001b[1;32m 937\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmax_completion_tokens\u001b[39m\u001b[38;5;124m\"\u001b[39m: max_completion_tokens,\n\u001b[1;32m 938\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmax_tokens\u001b[39m\u001b[38;5;124m\"\u001b[39m: max_tokens,\n\u001b[1;32m 939\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmetadata\u001b[39m\u001b[38;5;124m\"\u001b[39m: metadata,\n\u001b[1;32m 940\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodalities\u001b[39m\u001b[38;5;124m\"\u001b[39m: modalities,\n\u001b[1;32m 941\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mn\u001b[39m\u001b[38;5;124m\"\u001b[39m: n,\n\u001b[1;32m 942\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mparallel_tool_calls\u001b[39m\u001b[38;5;124m\"\u001b[39m: parallel_tool_calls,\n\u001b[1;32m 943\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mprediction\u001b[39m\u001b[38;5;124m\"\u001b[39m: prediction,\n\u001b[1;32m 944\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpresence_penalty\u001b[39m\u001b[38;5;124m\"\u001b[39m: presence_penalty,\n\u001b[1;32m 945\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mreasoning_effort\u001b[39m\u001b[38;5;124m\"\u001b[39m: reasoning_effort,\n\u001b[1;32m 946\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresponse_format\u001b[39m\u001b[38;5;124m\"\u001b[39m: response_format,\n\u001b[1;32m 947\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mseed\u001b[39m\u001b[38;5;124m\"\u001b[39m: seed,\n\u001b[1;32m 948\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mservice_tier\u001b[39m\u001b[38;5;124m\"\u001b[39m: service_tier,\n\u001b[1;32m 949\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstop\u001b[39m\u001b[38;5;124m\"\u001b[39m: stop,\n\u001b[1;32m 950\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstore\u001b[39m\u001b[38;5;124m\"\u001b[39m: store,\n\u001b[1;32m 951\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstream\u001b[39m\u001b[38;5;124m\"\u001b[39m: stream,\n\u001b[1;32m 952\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstream_options\u001b[39m\u001b[38;5;124m\"\u001b[39m: stream_options,\n\u001b[1;32m 953\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtemperature\u001b[39m\u001b[38;5;124m\"\u001b[39m: temperature,\n\u001b[1;32m 954\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtool_choice\u001b[39m\u001b[38;5;124m\"\u001b[39m: tool_choice,\n\u001b[1;32m 955\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtools\u001b[39m\u001b[38;5;124m\"\u001b[39m: tools,\n\u001b[1;32m 956\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtop_logprobs\u001b[39m\u001b[38;5;124m\"\u001b[39m: top_logprobs,\n\u001b[1;32m 957\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtop_p\u001b[39m\u001b[38;5;124m\"\u001b[39m: top_p,\n\u001b[1;32m 958\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muser\u001b[39m\u001b[38;5;124m\"\u001b[39m: user,\n\u001b[1;32m 959\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mweb_search_options\u001b[39m\u001b[38;5;124m\"\u001b[39m: web_search_options,\n\u001b[1;32m 960\u001b[0m },\n\u001b[1;32m 961\u001b[0m completion_create_params\u001b[38;5;241m.\u001b[39mCompletionCreateParamsStreaming\n\u001b[1;32m 962\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m stream\n\u001b[1;32m 963\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m completion_create_params\u001b[38;5;241m.\u001b[39mCompletionCreateParamsNonStreaming,\n\u001b[1;32m 964\u001b[0m ),\n\u001b[1;32m 965\u001b[0m options\u001b[38;5;241m=\u001b[39mmake_request_options(\n\u001b[1;32m 966\u001b[0m extra_headers\u001b[38;5;241m=\u001b[39mextra_headers, extra_query\u001b[38;5;241m=\u001b[39mextra_query, extra_body\u001b[38;5;241m=\u001b[39mextra_body, timeout\u001b[38;5;241m=\u001b[39mtimeout\n\u001b[1;32m 967\u001b[0m ),\n\u001b[1;32m 968\u001b[0m cast_to\u001b[38;5;241m=\u001b[39mChatCompletion,\n\u001b[1;32m 969\u001b[0m stream\u001b[38;5;241m=\u001b[39mstream \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[1;32m 970\u001b[0m stream_cls\u001b[38;5;241m=\u001b[39mStream[ChatCompletionChunk],\n\u001b[1;32m 971\u001b[0m )\n",
427
+ "File \u001b[0;32m/opt/anaconda3/lib/python3.11/site-packages/openai/_base_client.py:1242\u001b[0m, in \u001b[0;36mSyncAPIClient.post\u001b[0;34m(self, path, cast_to, body, options, files, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1228\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpost\u001b[39m(\n\u001b[1;32m 1229\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 1230\u001b[0m path: \u001b[38;5;28mstr\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1237\u001b[0m stream_cls: \u001b[38;5;28mtype\u001b[39m[_StreamT] \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 1238\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m ResponseT \u001b[38;5;241m|\u001b[39m _StreamT:\n\u001b[1;32m 1239\u001b[0m opts \u001b[38;5;241m=\u001b[39m FinalRequestOptions\u001b[38;5;241m.\u001b[39mconstruct(\n\u001b[1;32m 1240\u001b[0m method\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpost\u001b[39m\u001b[38;5;124m\"\u001b[39m, url\u001b[38;5;241m=\u001b[39mpath, json_data\u001b[38;5;241m=\u001b[39mbody, files\u001b[38;5;241m=\u001b[39mto_httpx_files(files), \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39moptions\n\u001b[1;32m 1241\u001b[0m )\n\u001b[0;32m-> 1242\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m cast(ResponseT, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrequest(cast_to, opts, stream\u001b[38;5;241m=\u001b[39mstream, stream_cls\u001b[38;5;241m=\u001b[39mstream_cls))\n",
428
+ "File \u001b[0;32m/opt/anaconda3/lib/python3.11/site-packages/openai/_base_client.py:1037\u001b[0m, in \u001b[0;36mSyncAPIClient.request\u001b[0;34m(self, cast_to, options, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1034\u001b[0m err\u001b[38;5;241m.\u001b[39mresponse\u001b[38;5;241m.\u001b[39mread()\n\u001b[1;32m 1036\u001b[0m log\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRe-raising status error\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m-> 1037\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_status_error_from_response(err\u001b[38;5;241m.\u001b[39mresponse) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1039\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m 1041\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m response \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcould not resolve response (should never happen)\u001b[39m\u001b[38;5;124m\"\u001b[39m\n",
429
+ "\u001b[0;31mRateLimitError\u001b[0m: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}"
430
+ ]
431
+ }
432
+ ],
433
+ "source": [
434
+ "\n",
435
+ "# Example query\n",
436
+ "query = \"¿Cuál es el origen del JuJutsu en Japón?\"\n",
437
+ "retrieved = search(query)\n",
438
+ "\n",
439
+ "print(\"🔹 Sin RAG:\")\n",
440
+ "print(chat_no_rag(query))\n",
441
+ "\n",
442
+ "print(\"\\n🔹 Con RAG:\")\n",
443
+ "print(chat_with_rag(query, retrieved))\n",
444
+ "\n",
445
+ "print(\"\\n🔹 Con RAG + Prompt mejorado:\")\n",
446
+ "print(chat_with_rag_enhanced(query, retrieved))\n"
447
+ ]
448
+ },
449
+ {
450
+ "cell_type": "code",
451
+ "execution_count": null,
452
+ "id": "0b852f41-946b-4684-b3c8-5ee2b416710b",
453
+ "metadata": {},
454
+ "outputs": [],
455
+ "source": []
456
+ }
457
+ ],
458
+ "metadata": {
459
+ "kernelspec": {
460
+ "display_name": "Python 3 (ipykernel)",
461
+ "language": "python",
462
+ "name": "python3"
463
+ },
464
+ "language_info": {
465
+ "codemirror_mode": {
466
+ "name": "ipython",
467
+ "version": 3
468
+ },
469
+ "file_extension": ".py",
470
+ "mimetype": "text/x-python",
471
+ "name": "python",
472
+ "nbconvert_exporter": "python",
473
+ "pygments_lexer": "ipython3",
474
+ "version": "3.11.7"
475
+ }
476
+ },
477
+ "nbformat": 4,
478
+ "nbformat_minor": 5
479
+ }
.ipynb_checkpoints/rag_openai_gpt35_ready-checkpoint.ipynb ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "ebeba428",
6
+ "metadata": {},
7
+ "source": [
8
+ "# ✅ RAG JuJutsu PoC (Notebook with Joblib, FAISS, ChatGPT API)"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": null,
14
+ "id": "8bdfd3c8",
15
+ "metadata": {
16
+ "scrolled": true
17
+ },
18
+ "outputs": [],
19
+ "source": [
20
+ "\n",
21
+ "!pip install --quiet openai langchain faiss-cpu PyPDF2 sentence-transformers joblib\n",
22
+ "!pip install ipywidgets==7.7.2\n",
23
+ "!jupyter nbextension enable --py widgetsnbextension\n",
24
+ "!jupyter notebook\n"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": null,
30
+ "id": "49ee7721",
31
+ "metadata": {},
32
+ "outputs": [],
33
+ "source": [
34
+ "from PyPDF2 import PdfReader\n",
35
+ "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
36
+ "\n",
37
+ "def load_pdf_chunks(pdf_path):\n",
38
+ " reader = PdfReader(pdf_path)\n",
39
+ " raw_text = \"\"\n",
40
+ " for page in reader.pages:\n",
41
+ " raw_text += page.extract_text() + \"\\n\"\n",
42
+ "\n",
43
+ " splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)\n",
44
+ " return splitter.split_text(raw_text)\n",
45
+ "\n",
46
+ "chunks = load_pdf_chunks(\"JuJutsu-Contexto-Significado-Conexiones-Historia.pdf\")\n",
47
+ "print(f\"Loaded {len(chunks)} chunks\")\n"
48
+ ]
49
+ },
50
+ {
51
+ "cell_type": "code",
52
+ "execution_count": null,
53
+ "id": "8109b626-0179-43e2-b924-65afe9af1e4e",
54
+ "metadata": {},
55
+ "outputs": [],
56
+ "source": [
57
+ "import openai"
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": null,
63
+ "id": "371c637e",
64
+ "metadata": {},
65
+ "outputs": [],
66
+ "source": [
67
+ "\n",
68
+ "import faiss\n",
69
+ "import numpy as np\n",
70
+ "import joblib\n",
71
+ "\n",
72
+ "def get_openai_embeddings(texts):\n",
73
+ " embeddings = []\n",
74
+ " for text in texts:\n",
75
+ " response = openai.Embedding.create(\n",
76
+ " model=\"text-embedding-3-small\",\n",
77
+ " input=text\n",
78
+ " )\n",
79
+ " vector = response['data'][0]['embedding']\n",
80
+ " embeddings.append(vector)\n",
81
+ " return np.array(embeddings)\n",
82
+ "\n",
83
+ "embeddings = get_openai_embeddings(chunks)\n",
84
+ "index = faiss.IndexFlatL2(embeddings.shape[1])\n",
85
+ "index.add(np.array(embeddings))\n",
86
+ "\n",
87
+ "joblib.dump((chunks, index), \"rag_model.joblib\")\n",
88
+ "print(\"Chunks and index serialized to rag_model.joblib\")\n"
89
+ ]
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "execution_count": null,
94
+ "id": "28ce4963",
95
+ "metadata": {},
96
+ "outputs": [],
97
+ "source": [
98
+ "\n",
99
+ "import joblib\n",
100
+ "chunks, index = joblib.load(\"rag_model.joblib\")\n",
101
+ "print(\"Chunks and index loaded from rag_model.joblib\")\n"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": null,
107
+ "id": "51a89e77",
108
+ "metadata": {},
109
+ "outputs": [],
110
+ "source": [
111
+ "\n",
112
+ "def search(query, k=3):\n",
113
+ " response = openai.Embedding.create(\n",
114
+ " model=\"text-embedding-3-small\",\n",
115
+ " input=query\n",
116
+ " )\n",
117
+ " query_vec = np.array([response['data'][0]['embedding']])\n",
118
+ " scores, indices = index.search(query_vec, k)\n",
119
+ " return [chunks[i] for i in indices[0]]\n"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": null,
125
+ "id": "34315775",
126
+ "metadata": {},
127
+ "outputs": [],
128
+ "source": [
129
+ "\n",
130
+ "import os\n",
131
+ "import openai\n",
132
+ "from openai import OpenAI\n",
133
+ "\n",
134
+ "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\")\n",
135
+ "client = OpenAI()\n",
136
+ "\n",
137
+ "def chat_no_rag(question):\n",
138
+ " response = client.chat.completions.create(\n",
139
+ " model=\"gpt-3.5-turbo\",\n",
140
+ " messages=[\n",
141
+ " {\"role\": \"user\", \"content\": question}\n",
142
+ " ],\n",
143
+ " temperature=0.5,\n",
144
+ " max_tokens=200,\n",
145
+ " )\n",
146
+ " return response.choices[0].message.content\n",
147
+ "\n",
148
+ "def chat_with_rag(question, retrieved_chunks):\n",
149
+ " context = \"\\n\".join(retrieved_chunks)\n",
150
+ " prompt = f\"Usa el siguiente contexto para responder la pregunta:\\n\\n{context}\\n\\nPregunta: {question}\"\n",
151
+ "\n",
152
+ " response = client.chat.completions.create(\n",
153
+ " model=\"gpt-3.5-turbo\",\n",
154
+ " messages=[\n",
155
+ " {\"role\": \"user\", \"content\": prompt}\n",
156
+ " ],\n",
157
+ " temperature=0.3,\n",
158
+ " max_tokens=200,\n",
159
+ " )\n",
160
+ " return response.choices[0].message.content\n",
161
+ "\n",
162
+ "def chat_with_rag_enhanced(question, retrieved_chunks):\n",
163
+ " context = \"\\n\".join(retrieved_chunks)\n",
164
+ " prompt = (\n",
165
+ " \"Eres un experto en historia marcial. \"\n",
166
+ " \"Usa el siguiente contexto histórico para responder con precisión y detalle.\\n\\n\"\n",
167
+ " f\"Contexto:\\n{context}\\n\\n\"\n",
168
+ " f\"Pregunta: {question}\\nRespuesta:\"\n",
169
+ " )\n",
170
+ "\n",
171
+ " response = client.chat.completions.create(\n",
172
+ " model=\"gpt-3.5-turbo\",\n",
173
+ " messages=[\n",
174
+ " {\"role\": \"user\", \"content\": prompt}\n",
175
+ " ],\n",
176
+ " temperature=0.2,\n",
177
+ " max_tokens=200,\n",
178
+ " )\n",
179
+ " return response.choices[0].message.content\n"
180
+ ]
181
+ },
182
+ {
183
+ "cell_type": "code",
184
+ "execution_count": null,
185
+ "id": "900dfdfa",
186
+ "metadata": {},
187
+ "outputs": [],
188
+ "source": [
189
+ "\n",
190
+ "# Example query\n",
191
+ "query = \"¿Cuál es el origen del JuJutsu en Japón?\"\n",
192
+ "retrieved = search(query)\n",
193
+ "\n",
194
+ "print(\"🔹 Sin RAG:\")\n",
195
+ "print(chat_no_rag(query))\n",
196
+ "\n",
197
+ "print(\"\\n🔹 Con RAG:\")\n",
198
+ "print(chat_with_rag(query, retrieved))\n",
199
+ "\n",
200
+ "print(\"\\n🔹 Con RAG + Prompt mejorado:\")\n",
201
+ "print(chat_with_rag_enhanced(query, retrieved))\n"
202
+ ]
203
+ }
204
+ ],
205
+ "metadata": {
206
+ "kernelspec": {
207
+ "display_name": "Python 3 (ipykernel)",
208
+ "language": "python",
209
+ "name": "python3"
210
+ },
211
+ "language_info": {
212
+ "codemirror_mode": {
213
+ "name": "ipython",
214
+ "version": 3
215
+ },
216
+ "file_extension": ".py",
217
+ "mimetype": "text/x-python",
218
+ "name": "python",
219
+ "nbconvert_exporter": "python",
220
+ "pygments_lexer": "ipython3",
221
+ "version": "3.11.7"
222
+ }
223
+ },
224
+ "nbformat": 4,
225
+ "nbformat_minor": 5
226
+ }
rag_model.joblib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:191c72a285f0f1742892852d93ae4ed4a1fc5f003ff2d4a505ae04027791536b
3
- size 92064432
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:46b46113fa297dcb1afb5896d2f1963dfeca646da4cad921e81ddbf34112639c
3
+ size 2186758
rag_openai_gpt35_ready.ipynb ADDED
@@ -0,0 +1,701 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "ebeba428",
6
+ "metadata": {},
7
+ "source": [
8
+ "# ✅ RAG JuJutsu PoC (Notebook with Joblib, FAISS, ChatGPT API)"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 2,
14
+ "id": "8bdfd3c8",
15
+ "metadata": {
16
+ "scrolled": true
17
+ },
18
+ "outputs": [
19
+ {
20
+ "name": "stdout",
21
+ "output_type": "stream",
22
+ "text": [
23
+ "Requirement already satisfied: ipywidgets==7.7.2 in /opt/anaconda3/lib/python3.11/site-packages (7.7.2)\n",
24
+ "Requirement already satisfied: ipykernel>=4.5.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (6.28.0)\n",
25
+ "Requirement already satisfied: ipython-genutils~=0.2.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (0.2.0)\n",
26
+ "Requirement already satisfied: traitlets>=4.3.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (5.7.1)\n",
27
+ "Requirement already satisfied: widgetsnbextension~=3.6.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (3.6.10)\n",
28
+ "Requirement already satisfied: ipython>=4.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (8.20.0)\n",
29
+ "Requirement already satisfied: jupyterlab-widgets<3,>=1.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipywidgets==7.7.2) (1.1.11)\n",
30
+ "Requirement already satisfied: appnope in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (0.1.2)\n",
31
+ "Requirement already satisfied: comm>=0.1.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (0.1.2)\n",
32
+ "Requirement already satisfied: debugpy>=1.6.5 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (1.6.7)\n",
33
+ "Requirement already satisfied: jupyter-client>=6.1.12 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (8.6.0)\n",
34
+ "Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (5.5.0)\n",
35
+ "Requirement already satisfied: matplotlib-inline>=0.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (0.1.6)\n",
36
+ "Requirement already satisfied: nest-asyncio in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (1.6.0)\n",
37
+ "Requirement already satisfied: packaging in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (23.2)\n",
38
+ "Requirement already satisfied: psutil in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (5.9.0)\n",
39
+ "Requirement already satisfied: pyzmq>=24 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (25.1.2)\n",
40
+ "Requirement already satisfied: tornado>=6.1 in /opt/anaconda3/lib/python3.11/site-packages (from ipykernel>=4.5.1->ipywidgets==7.7.2) (6.3.3)\n",
41
+ "Requirement already satisfied: decorator in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (5.1.1)\n",
42
+ "Requirement already satisfied: jedi>=0.16 in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (0.18.1)\n",
43
+ "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (3.0.43)\n",
44
+ "Requirement already satisfied: pygments>=2.4.0 in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (2.15.1)\n",
45
+ "Requirement already satisfied: stack-data in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (0.2.0)\n",
46
+ "Requirement already satisfied: pexpect>4.3 in /opt/anaconda3/lib/python3.11/site-packages (from ipython>=4.0.0->ipywidgets==7.7.2) (4.8.0)\n",
47
+ "Requirement already satisfied: notebook>=4.4.1 in /opt/anaconda3/lib/python3.11/site-packages (from widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (7.3.2)\n",
48
+ "Requirement already satisfied: parso<0.9.0,>=0.8.0 in /opt/anaconda3/lib/python3.11/site-packages (from jedi>=0.16->ipython>=4.0.0->ipywidgets==7.7.2) (0.8.3)\n",
49
+ "Requirement already satisfied: python-dateutil>=2.8.2 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-client>=6.1.12->ipykernel>=4.5.1->ipywidgets==7.7.2) (2.9.0.post0)\n",
50
+ "Requirement already satisfied: platformdirs>=2.5 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-core!=5.0.*,>=4.12->ipykernel>=4.5.1->ipywidgets==7.7.2) (3.10.0)\n",
51
+ "Requirement already satisfied: jupyter-server<3,>=2.4.0 in /opt/anaconda3/lib/python3.11/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.10.0)\n",
52
+ "Requirement already satisfied: jupyterlab-server<3,>=2.27.1 in /opt/anaconda3/lib/python3.11/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.27.3)\n",
53
+ "Requirement already satisfied: jupyterlab<4.4,>=4.3.4 in /opt/anaconda3/lib/python3.11/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.3.4)\n",
54
+ "Requirement already satisfied: notebook-shim<0.3,>=0.2 in /opt/anaconda3/lib/python3.11/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.2.3)\n",
55
+ "Requirement already satisfied: ptyprocess>=0.5 in /opt/anaconda3/lib/python3.11/site-packages (from pexpect>4.3->ipython>=4.0.0->ipywidgets==7.7.2) (0.7.0)\n",
56
+ "Requirement already satisfied: wcwidth in /opt/anaconda3/lib/python3.11/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython>=4.0.0->ipywidgets==7.7.2) (0.2.5)\n",
57
+ "Requirement already satisfied: executing in /opt/anaconda3/lib/python3.11/site-packages (from stack-data->ipython>=4.0.0->ipywidgets==7.7.2) (0.8.3)\n",
58
+ "Requirement already satisfied: asttokens in /opt/anaconda3/lib/python3.11/site-packages (from stack-data->ipython>=4.0.0->ipywidgets==7.7.2) (2.0.5)\n",
59
+ "Requirement already satisfied: pure-eval in /opt/anaconda3/lib/python3.11/site-packages (from stack-data->ipython>=4.0.0->ipywidgets==7.7.2) (0.2.2)\n",
60
+ "Requirement already satisfied: anyio>=3.1.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.2.0)\n",
61
+ "Requirement already satisfied: argon2-cffi in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (21.3.0)\n",
62
+ "Requirement already satisfied: jinja2 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (3.1.3)\n",
63
+ "Requirement already satisfied: jupyter-events>=0.6.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.8.0)\n",
64
+ "Requirement already satisfied: jupyter-server-terminals in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.4.4)\n",
65
+ "Requirement already satisfied: nbconvert>=6.4.4 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (7.16.3)\n",
66
+ "Requirement already satisfied: nbformat>=5.3.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (5.9.2)\n",
67
+ "Requirement already satisfied: overrides in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (7.4.0)\n",
68
+ "Requirement already satisfied: prometheus-client in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.14.1)\n",
69
+ "Requirement already satisfied: send2trash>=1.8.2 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.8.2)\n",
70
+ "Requirement already satisfied: terminado>=0.8.3 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.17.1)\n",
71
+ "Requirement already satisfied: websocket-client in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.58.0)\n",
72
+ "Requirement already satisfied: async-lru>=1.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.4)\n",
73
+ "Requirement already satisfied: httpx>=0.25.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.26.0)\n",
74
+ "Requirement already satisfied: jupyter-lsp>=2.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.2.0)\n",
75
+ "Requirement already satisfied: setuptools>=40.8.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (68.2.2)\n",
76
+ "Requirement already satisfied: babel>=2.10 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.11.0)\n",
77
+ "Requirement already satisfied: json5>=0.9.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.9.6)\n",
78
+ "Requirement already satisfied: jsonschema>=4.18.0 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.19.2)\n",
79
+ "Requirement already satisfied: requests>=2.31 in /opt/anaconda3/lib/python3.11/site-packages (from jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.32.3)\n",
80
+ "Requirement already satisfied: six>=1.5 in /opt/anaconda3/lib/python3.11/site-packages (from python-dateutil>=2.8.2->jupyter-client>=6.1.12->ipykernel>=4.5.1->ipywidgets==7.7.2) (1.17.0)\n",
81
+ "Requirement already satisfied: idna>=2.8 in /opt/anaconda3/lib/python3.11/site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (3.4)\n",
82
+ "Requirement already satisfied: sniffio>=1.1 in /opt/anaconda3/lib/python3.11/site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.3.0)\n",
83
+ "Requirement already satisfied: pytz>=2015.7 in /opt/anaconda3/lib/python3.11/site-packages (from babel>=2.10->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2025.2)\n",
84
+ "Requirement already satisfied: certifi in /opt/anaconda3/lib/python3.11/site-packages (from httpx>=0.25.0->jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2025.1.31)\n",
85
+ "Requirement already satisfied: httpcore==1.* in /opt/anaconda3/lib/python3.11/site-packages (from httpx>=0.25.0->jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.0.2)\n",
86
+ "Requirement already satisfied: h11<0.15,>=0.13 in /opt/anaconda3/lib/python3.11/site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab<4.4,>=4.3.4->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.14.0)\n",
87
+ "Requirement already satisfied: MarkupSafe>=2.0 in /opt/anaconda3/lib/python3.11/site-packages (from jinja2->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.1.3)\n",
88
+ "Requirement already satisfied: attrs>=22.2.0 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (23.1.0)\n",
89
+ "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2023.7.1)\n",
90
+ "Requirement already satisfied: referencing>=0.28.4 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.30.2)\n",
91
+ "Requirement already satisfied: rpds-py>=0.7.1 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.10.6)\n",
92
+ "Requirement already satisfied: python-json-logger>=2.0.4 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.7)\n",
93
+ "Requirement already satisfied: pyyaml>=5.3 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (6.0.1)\n",
94
+ "Requirement already satisfied: rfc3339-validator in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.1.4)\n",
95
+ "Requirement already satisfied: rfc3986-validator>=0.1.1 in /opt/anaconda3/lib/python3.11/site-packages (from jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.1.1)\n",
96
+ "Requirement already satisfied: beautifulsoup4 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.12.2)\n",
97
+ "Requirement already satisfied: bleach!=5.0.0 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (4.1.0)\n",
98
+ "Requirement already satisfied: defusedxml in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.7.1)\n",
99
+ "Requirement already satisfied: jupyterlab-pygments in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.1.2)\n",
100
+ "Requirement already satisfied: mistune<4,>=2.0.3 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.4)\n",
101
+ "Requirement already satisfied: nbclient>=0.5.0 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.8.0)\n",
102
+ "Requirement already satisfied: pandocfilters>=1.4.1 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.5.0)\n",
103
+ "Requirement already satisfied: tinycss2 in /opt/anaconda3/lib/python3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.2.1)\n",
104
+ "Requirement already satisfied: fastjsonschema in /opt/anaconda3/lib/python3.11/site-packages (from nbformat>=5.3.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.16.2)\n",
105
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /opt/anaconda3/lib/python3.11/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.4)\n",
106
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/anaconda3/lib/python3.11/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.0.7)\n",
107
+ "Requirement already satisfied: argon2-cffi-bindings in /opt/anaconda3/lib/python3.11/site-packages (from argon2-cffi->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (21.2.0)\n",
108
+ "Requirement already satisfied: webencodings in /opt/anaconda3/lib/python3.11/site-packages (from bleach!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (0.5.1)\n",
109
+ "Requirement already satisfied: fqdn in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.5.1)\n",
110
+ "Requirement already satisfied: isoduration in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (20.11.0)\n",
111
+ "Requirement already satisfied: jsonpointer>1.13 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.1)\n",
112
+ "Requirement already satisfied: uri-template in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.3.0)\n",
113
+ "Requirement already satisfied: webcolors>=1.11 in /opt/anaconda3/lib/python3.11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (24.11.1)\n",
114
+ "Requirement already satisfied: cffi>=1.0.1 in /opt/anaconda3/lib/python3.11/site-packages (from argon2-cffi-bindings->argon2-cffi->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.16.0)\n",
115
+ "Requirement already satisfied: soupsieve>1.2 in /opt/anaconda3/lib/python3.11/site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.5)\n",
116
+ "Requirement already satisfied: pycparser in /opt/anaconda3/lib/python3.11/site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (2.21)\n",
117
+ "Requirement already satisfied: arrow>=0.15.0 in /opt/anaconda3/lib/python3.11/site-packages (from isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.6.0->jupyter-server<3,>=2.4.0->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets==7.7.2) (1.2.3)\n",
118
+ "usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]\n",
119
+ " [--paths] [--json] [--debug]\n",
120
+ " [subcommand]\n",
121
+ "\n",
122
+ "Jupyter: Interactive Computing\n",
123
+ "\n",
124
+ "positional arguments:\n",
125
+ " subcommand the subcommand to launch\n",
126
+ "\n",
127
+ "options:\n",
128
+ " -h, --help show this help message and exit\n",
129
+ " --version show the versions of core jupyter packages and exit\n",
130
+ " --config-dir show Jupyter config dir\n",
131
+ " --data-dir show Jupyter data dir\n",
132
+ " --runtime-dir show Jupyter runtime dir\n",
133
+ " --paths show all Jupyter paths. Add --json for machine-readable\n",
134
+ " format.\n",
135
+ " --json output paths as machine-readable json\n",
136
+ " --debug output debug information about paths\n",
137
+ "\n",
138
+ "Available subcommands: console dejavu events execute kernel kernelspec lab\n",
139
+ "labextension labhub migrate nbconvert notebook qtconsole run server\n",
140
+ "troubleshoot trust\n",
141
+ "\n",
142
+ "Jupyter command `jupyter-nbextension` not found.\n",
143
+ "\u001b[32m[I 2025-06-20 15:36:39.629 ServerApp]\u001b[m Package notebook took 0.0000s to import\n",
144
+ "\u001b[32m[I 2025-06-20 15:36:39.804 ServerApp]\u001b[m Package aext_assistant took 0.1753s to import\n",
145
+ "\u001b[32m[I 2025-06-20 15:36:39.805 ServerApp]\u001b[m Package aext_core took 0.0010s to import\n",
146
+ "\u001b[33m[W 2025-06-20 15:36:39.812 ServerApp]\u001b[m aext_panels | error adding extension (enabled: True): The module 'aext_panels' could not be found (cannot import name 'AuthConfig' from 'anaconda_cloud_auth.client' (/opt/anaconda3/lib/python3.11/site-packages/anaconda_cloud_auth/client.py)). Are you sure the extension is installed?\n",
147
+ " Traceback (most recent call last):\n",
148
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/manager.py\", line 321, in add_extension\n",
149
+ " extpkg = ExtensionPackage(name=extension_name, enabled=enabled)\n",
150
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
151
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/manager.py\", line 185, in __init__\n",
152
+ " self._load_metadata()\n",
153
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/manager.py\", line 200, in _load_metadata\n",
154
+ " raise ExtensionModuleNotFound(msg) from None\n",
155
+ " jupyter_server.extension.utils.ExtensionModuleNotFound: The module 'aext_panels' could not be found (cannot import name 'AuthConfig' from 'anaconda_cloud_auth.client' (/opt/anaconda3/lib/python3.11/site-packages/anaconda_cloud_auth/client.py)). Are you sure the extension is installed?\n",
156
+ "\u001b[32m[I 2025-06-20 15:36:39.814 ServerApp]\u001b[m Package aext_share_notebook took 0.0009s to import\n",
157
+ "\u001b[32m[I 2025-06-20 15:36:39.824 ServerApp]\u001b[m Package jupyter_lsp took 0.0104s to import\n",
158
+ "\u001b[33m[W 2025-06-20 15:36:39.824 ServerApp]\u001b[m A `_jupyter_server_extension_points` function was not found in jupyter_lsp. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.\n",
159
+ "\u001b[32m[I 2025-06-20 15:36:39.828 ServerApp]\u001b[m Package jupyter_server_terminals took 0.0042s to import\n",
160
+ "\u001b[32m[I 2025-06-20 15:36:39.829 ServerApp]\u001b[m Package jupyterlab took 0.0000s to import\n",
161
+ "\u001b[32m[I 2025-06-20 15:36:40.122 ServerApp]\u001b[m Package notebook_shim took 0.0000s to import\n",
162
+ "\u001b[33m[W 2025-06-20 15:36:40.122 ServerApp]\u001b[m A `_jupyter_server_extension_points` function was not found in notebook_shim. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.\n",
163
+ "\u001b[32m[I 2025-06-20 15:36:40.544 ServerApp]\u001b[m Package panel.io.jupyter_server_extension took 0.4215s to import\n",
164
+ "\u001b[32m[I 2025-06-20 15:36:40.544 ServerApp]\u001b[m aext_assistant | extension was successfully linked.\n",
165
+ "\u001b[32m[I 2025-06-20 15:36:40.544 ServerApp]\u001b[m aext_core | extension was successfully linked.\n",
166
+ "\u001b[32m[I 2025-06-20 15:36:40.545 ServerApp]\u001b[m aext_share_notebook | extension was successfully linked.\n",
167
+ "\u001b[32m[I 2025-06-20 15:36:40.545 ServerApp]\u001b[m jupyter_lsp | extension was successfully linked.\n",
168
+ "\u001b[32m[I 2025-06-20 15:36:40.546 ServerApp]\u001b[m jupyter_server_terminals | extension was successfully linked.\n",
169
+ "\u001b[32m[I 2025-06-20 15:36:40.548 ServerApp]\u001b[m jupyterlab | extension was successfully linked.\n",
170
+ "\u001b[32m[I 2025-06-20 15:36:40.549 ServerApp]\u001b[m notebook | extension was successfully linked.\n",
171
+ "\u001b[32m[I 2025-06-20 15:36:40.712 ServerApp]\u001b[m notebook_shim | extension was successfully linked.\n",
172
+ "\u001b[32m[I 2025-06-20 15:36:40.712 ServerApp]\u001b[m panel.io.jupyter_server_extension | extension was successfully linked.\n",
173
+ "\u001b[32m[I 2025-06-20 15:36:40.733 ServerApp]\u001b[m notebook_shim | extension was successfully loaded.\n",
174
+ "\u001b[32m[I 2025-06-20 15:36:40.734 ServerApp]\u001b[m Registered aext_assistant server extension\n",
175
+ "\u001b[32m[I 2025-06-20 15:36:40.734 ServerApp]\u001b[m aext_assistant | extension was successfully loaded.\n",
176
+ "\u001b[32m[I 2025-06-20 15:36:40.734 ServerApp]\u001b[m Registered aext_core server extension\n",
177
+ "\u001b[32m[I 2025-06-20 15:36:40.734 ServerApp]\u001b[m aext_core | extension was successfully loaded.\n",
178
+ "\u001b[32m[I 2025-06-20 15:36:40.734 ServerApp]\u001b[m Registered aext_share_notebook_server server extension\n",
179
+ "\u001b[32m[I 2025-06-20 15:36:40.734 ServerApp]\u001b[m aext_share_notebook | extension was successfully loaded.\n",
180
+ "\u001b[32m[I 2025-06-20 15:36:40.735 ServerApp]\u001b[m jupyter_lsp | extension was successfully loaded.\n",
181
+ "\u001b[32m[I 2025-06-20 15:36:40.736 ServerApp]\u001b[m jupyter_server_terminals | extension was successfully loaded.\n",
182
+ "\u001b[32m[I 2025-06-20 15:36:40.738 LabApp]\u001b[m JupyterLab extension loaded from /opt/anaconda3/lib/python3.11/site-packages/jupyterlab\n",
183
+ "\u001b[32m[I 2025-06-20 15:36:40.738 LabApp]\u001b[m JupyterLab application directory is /opt/anaconda3/share/jupyter/lab\n",
184
+ "\u001b[32m[I 2025-06-20 15:36:40.739 LabApp]\u001b[m Extension Manager is 'pypi'.\n",
185
+ "\u001b[32m[I 2025-06-20 15:36:40.755 ServerApp]\u001b[m jupyterlab | extension was successfully loaded.\n",
186
+ "\u001b[32m[I 2025-06-20 15:36:40.757 ServerApp]\u001b[m notebook | extension was successfully loaded.\n",
187
+ "\u001b[32m[I 2025-06-20 15:36:40.758 ServerApp]\u001b[m panel.io.jupyter_server_extension | extension was successfully loaded.\n",
188
+ "\u001b[32m[I 2025-06-20 15:36:40.759 ServerApp]\u001b[m The port 8888 is already in use, trying another port.\n",
189
+ "\u001b[32m[I 2025-06-20 15:36:40.759 ServerApp]\u001b[m The port 8889 is already in use, trying another port.\n",
190
+ "\u001b[32m[I 2025-06-20 15:36:40.759 ServerApp]\u001b[m The port 8890 is already in use, trying another port.\n",
191
+ "\u001b[32m[I 2025-06-20 15:36:40.760 ServerApp]\u001b[m Serving notebooks from local directory: /Users/ddiaz/Desktop/Proyectos_ImageMarker/JuJitsuPOC\n",
192
+ "\u001b[32m[I 2025-06-20 15:36:40.760 ServerApp]\u001b[m Jupyter Server 2.10.0 is running at:\n",
193
+ "\u001b[32m[I 2025-06-20 15:36:40.760 ServerApp]\u001b[m http://localhost:8891/tree?token=53dae3fcd0d912651e64cf45e29de3d9920a8fdccf3339e8\n",
194
+ "\u001b[32m[I 2025-06-20 15:36:40.760 ServerApp]\u001b[m http://127.0.0.1:8891/tree?token=53dae3fcd0d912651e64cf45e29de3d9920a8fdccf3339e8\n",
195
+ "\u001b[32m[I 2025-06-20 15:36:40.760 ServerApp]\u001b[m Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).\n",
196
+ "\u001b[35m[C 2025-06-20 15:36:40.762 ServerApp]\u001b[m \n",
197
+ " \n",
198
+ " To access the server, open this file in a browser:\n",
199
+ " file:///Users/ddiaz/Library/Jupyter/runtime/jpserver-74191-open.html\n",
200
+ " Or copy and paste one of these URLs:\n",
201
+ " http://localhost:8891/tree?token=53dae3fcd0d912651e64cf45e29de3d9920a8fdccf3339e8\n",
202
+ " http://127.0.0.1:8891/tree?token=53dae3fcd0d912651e64cf45e29de3d9920a8fdccf3339e8\n",
203
+ "\u001b[32m[I 2025-06-20 15:36:41.078 ServerApp]\u001b[m Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server\n",
204
+ "0.00s - Debugger warning: It seems that frozen modules are being used, which may\n",
205
+ "0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off\n",
206
+ "0.00s - to python to disable frozen modules.\n",
207
+ "0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.\n",
208
+ "\u001b[33m[W 2025-06-20 15:36:42.687 ServerApp]\u001b[m wrote error: 'Forbidden'\n",
209
+ " Traceback (most recent call last):\n",
210
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
211
+ " result = await result\n",
212
+ " ^^^^^^^^^^^^\n",
213
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/aext_assistant_server/handlers.py\", line 117, in get\n",
214
+ " raise HTTPError(403, reason=\"missing nucleus_token\")\n",
215
+ " tornado.web.HTTPError: HTTP 403: missing nucleus_token\n",
216
+ "\u001b[33m[W 2025-06-20 15:36:42.689 ServerApp]\u001b[m 403 GET /aext_assistant_server/nucleus_token?1750455402620 (e1bb6698e462478ab1b1bdda87374748@::1) 3.10ms referer=http://localhost:8891/tree\n",
217
+ "\u001b[33m[W 2025-06-20 15:36:46.989 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455406980 (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
218
+ "\u001b[33m[W 2025-06-20 15:36:46.990 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa'\n",
219
+ " Traceback (most recent call last):\n",
220
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
221
+ " result = await result\n",
222
+ " ^^^^^^^^^^^^\n",
223
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
224
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
225
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
226
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
227
+ " self._check_kernel_id(kernel_id)\n",
228
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
229
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
230
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa)\n",
231
+ "\u001b[33m[W 2025-06-20 15:36:46.998 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455406980 (e1bb6698e462478ab1b1bdda87374748@::1) 12.23ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_jujutsu_poc_joblib.ipynb?\n",
232
+ "\u001b[33m[W 2025-06-20 15:36:47.991 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
233
+ "\u001b[33m[W 2025-06-20 15:36:48.019 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (e1bb6698e462478ab1b1bdda87374748@::1) 29.49ms referer=None\n",
234
+ "\u001b[33m[W 2025-06-20 15:36:48.026 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455408020 (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
235
+ "\u001b[33m[W 2025-06-20 15:36:48.026 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa'\n",
236
+ " Traceback (most recent call last):\n",
237
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
238
+ " result = await result\n",
239
+ " ^^^^^^^^^^^^\n",
240
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
241
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
242
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
243
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
244
+ " self._check_kernel_id(kernel_id)\n",
245
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
246
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
247
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa)\n",
248
+ "\u001b[33m[W 2025-06-20 15:36:48.027 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455408020 (e1bb6698e462478ab1b1bdda87374748@::1) 1.63ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_jujutsu_poc_joblib.ipynb?\n",
249
+ "\u001b[33m[W 2025-06-20 15:36:50.989 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455410980 (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
250
+ "\u001b[33m[W 2025-06-20 15:36:50.989 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf'\n",
251
+ " Traceback (most recent call last):\n",
252
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
253
+ " result = await result\n",
254
+ " ^^^^^^^^^^^^\n",
255
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
256
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
257
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
258
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
259
+ " self._check_kernel_id(kernel_id)\n",
260
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
261
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
262
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf)\n",
263
+ "\u001b[33m[W 2025-06-20 15:36:50.992 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455410980 (e1bb6698e462478ab1b1bdda87374748@::1) 6.25ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_openai_gpt35_ready.ipynb?\n",
264
+ "\u001b[33m[W 2025-06-20 15:36:50.992 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
265
+ "\u001b[33m[W 2025-06-20 15:36:50.994 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (e1bb6698e462478ab1b1bdda87374748@::1) 7.37ms referer=None\n",
266
+ "\u001b[33m[W 2025-06-20 15:36:50.998 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455410995 (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
267
+ "\u001b[33m[W 2025-06-20 15:36:50.998 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa'\n",
268
+ " Traceback (most recent call last):\n",
269
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
270
+ " result = await result\n",
271
+ " ^^^^^^^^^^^^\n",
272
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
273
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
274
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
275
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
276
+ " self._check_kernel_id(kernel_id)\n",
277
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
278
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
279
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa)\n",
280
+ "\u001b[33m[W 2025-06-20 15:36:50.999 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455410995 (e1bb6698e462478ab1b1bdda87374748@::1) 1.96ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_jujutsu_poc_joblib.ipynb?\n",
281
+ "\u001b[33m[W 2025-06-20 15:36:51.990 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
282
+ "\u001b[33m[W 2025-06-20 15:36:51.992 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (e1bb6698e462478ab1b1bdda87374748@::1) 3.70ms referer=None\n",
283
+ "\u001b[33m[W 2025-06-20 15:36:51.997 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455411993 (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
284
+ "\u001b[33m[W 2025-06-20 15:36:51.997 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf'\n",
285
+ " Traceback (most recent call last):\n",
286
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
287
+ " result = await result\n",
288
+ " ^^^^^^^^^^^^\n",
289
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
290
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
291
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
292
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
293
+ " self._check_kernel_id(kernel_id)\n",
294
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
295
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
296
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf)\n",
297
+ "\u001b[33m[W 2025-06-20 15:36:52.000 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455411993 (e1bb6698e462478ab1b1bdda87374748@::1) 3.70ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_openai_gpt35_ready.ipynb?\n",
298
+ "\u001b[33m[W 2025-06-20 15:36:52.991 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
299
+ "\u001b[33m[W 2025-06-20 15:36:52.992 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (e1bb6698e462478ab1b1bdda87374748@::1) 3.42ms referer=None\n",
300
+ "\u001b[33m[W 2025-06-20 15:36:52.998 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455412993 (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
301
+ "\u001b[33m[W 2025-06-20 15:36:52.998 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf'\n",
302
+ " Traceback (most recent call last):\n",
303
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
304
+ " result = await result\n",
305
+ " ^^^^^^^^^^^^\n",
306
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
307
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
308
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
309
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
310
+ " self._check_kernel_id(kernel_id)\n",
311
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
312
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
313
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf)\n",
314
+ "\u001b[33m[W 2025-06-20 15:36:53.000 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455412993 (e1bb6698e462478ab1b1bdda87374748@::1) 3.60ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_openai_gpt35_ready.ipynb?\n",
315
+ "\u001b[33m[W 2025-06-20 15:36:57.986 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
316
+ "\u001b[33m[W 2025-06-20 15:36:57.988 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (e1bb6698e462478ab1b1bdda87374748@::1) 2.83ms referer=None\n",
317
+ "\u001b[33m[W 2025-06-20 15:36:57.991 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455417989 (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
318
+ "\u001b[33m[W 2025-06-20 15:36:57.991 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa'\n",
319
+ " Traceback (most recent call last):\n",
320
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
321
+ " result = await result\n",
322
+ " ^^^^^^^^^^^^\n",
323
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
324
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
325
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
326
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
327
+ " self._check_kernel_id(kernel_id)\n",
328
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
329
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
330
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa)\n",
331
+ "\u001b[33m[W 2025-06-20 15:36:57.992 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455417989 (e1bb6698e462478ab1b1bdda87374748@::1) 1.93ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_jujutsu_poc_joblib.ipynb?\n",
332
+ "\u001b[33m[W 2025-06-20 15:36:58.994 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
333
+ "\u001b[33m[W 2025-06-20 15:36:58.996 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (e1bb6698e462478ab1b1bdda87374748@::1) 3.84ms referer=None\n",
334
+ "\u001b[33m[W 2025-06-20 15:36:59.002 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455418997 (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
335
+ "\u001b[33m[W 2025-06-20 15:36:59.002 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf'\n",
336
+ " Traceback (most recent call last):\n",
337
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
338
+ " result = await result\n",
339
+ " ^^^^^^^^^^^^\n",
340
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
341
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
342
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
343
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
344
+ " self._check_kernel_id(kernel_id)\n",
345
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
346
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
347
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf)\n",
348
+ "\u001b[33m[W 2025-06-20 15:36:59.004 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455418997 (e1bb6698e462478ab1b1bdda87374748@::1) 2.38ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_openai_gpt35_ready.ipynb?\n",
349
+ "\u001b[33m[W 2025-06-20 15:37:01.992 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
350
+ "\u001b[33m[W 2025-06-20 15:37:01.994 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (e1bb6698e462478ab1b1bdda87374748@::1) 3.18ms referer=None\n",
351
+ "\u001b[33m[W 2025-06-20 15:37:01.998 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455421995 (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
352
+ "\u001b[33m[W 2025-06-20 15:37:01.999 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf'\n",
353
+ " Traceback (most recent call last):\n",
354
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
355
+ " result = await result\n",
356
+ " ^^^^^^^^^^^^\n",
357
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
358
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
359
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
360
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
361
+ " self._check_kernel_id(kernel_id)\n",
362
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
363
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
364
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf)\n",
365
+ "\u001b[33m[W 2025-06-20 15:37:02.000 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455421995 (e1bb6698e462478ab1b1bdda87374748@::1) 3.65ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_openai_gpt35_ready.ipynb?\n",
366
+ "\u001b[33m[W 2025-06-20 15:37:04.002 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
367
+ "\u001b[33m[W 2025-06-20 15:37:04.005 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (e1bb6698e462478ab1b1bdda87374748@::1) 4.70ms referer=None\n",
368
+ "\u001b[33m[W 2025-06-20 15:37:04.010 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455424007 (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
369
+ "\u001b[33m[W 2025-06-20 15:37:04.011 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf'\n",
370
+ " Traceback (most recent call last):\n",
371
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
372
+ " result = await result\n",
373
+ " ^^^^^^^^^^^^\n",
374
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
375
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
376
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
377
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
378
+ " self._check_kernel_id(kernel_id)\n",
379
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
380
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
381
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf)\n",
382
+ "\u001b[33m[W 2025-06-20 15:37:04.012 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455424007 (e1bb6698e462478ab1b1bdda87374748@::1) 2.51ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_openai_gpt35_ready.ipynb?\n",
383
+ "\u001b[33m[W 2025-06-20 15:37:13.014 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
384
+ "\u001b[33m[W 2025-06-20 15:37:13.016 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (e1bb6698e462478ab1b1bdda87374748@::1) 4.59ms referer=None\n",
385
+ "\u001b[33m[W 2025-06-20 15:37:13.024 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455433018 (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
386
+ "\u001b[33m[W 2025-06-20 15:37:13.024 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa'\n",
387
+ " Traceback (most recent call last):\n",
388
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
389
+ " result = await result\n",
390
+ " ^^^^^^^^^^^^\n",
391
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
392
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
393
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
394
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
395
+ " self._check_kernel_id(kernel_id)\n",
396
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
397
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
398
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa)\n",
399
+ "\u001b[33m[W 2025-06-20 15:37:13.026 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455433018 (e1bb6698e462478ab1b1bdda87374748@::1) 3.66ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_jujutsu_poc_joblib.ipynb?\n",
400
+ "\u001b[33m[W 2025-06-20 15:37:28.064 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
401
+ "\u001b[33m[W 2025-06-20 15:37:28.066 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (e1bb6698e462478ab1b1bdda87374748@::1) 4.62ms referer=None\n",
402
+ "\u001b[33m[W 2025-06-20 15:37:28.073 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455448068 (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
403
+ "\u001b[33m[W 2025-06-20 15:37:28.073 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa'\n",
404
+ " Traceback (most recent call last):\n",
405
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
406
+ " result = await result\n",
407
+ " ^^^^^^^^^^^^\n",
408
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
409
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
410
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
411
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
412
+ " self._check_kernel_id(kernel_id)\n",
413
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
414
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
415
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa)\n",
416
+ "\u001b[33m[W 2025-06-20 15:37:28.075 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455448068 (e1bb6698e462478ab1b1bdda87374748@::1) 3.14ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_jujutsu_poc_joblib.ipynb?\n",
417
+ "\u001b[33m[W 2025-06-20 15:37:40.108 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
418
+ "\u001b[33m[W 2025-06-20 15:37:40.111 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf/channels?session_id=63a22fbe-d2d9-4ed1-b322-a3cecb79555a (e1bb6698e462478ab1b1bdda87374748@::1) 3.90ms referer=None\n",
419
+ "\u001b[33m[W 2025-06-20 15:37:40.118 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455460113 (::1): Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf\n",
420
+ "\u001b[33m[W 2025-06-20 15:37:40.118 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf'\n",
421
+ " Traceback (most recent call last):\n",
422
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
423
+ " result = await result\n",
424
+ " ^^^^^^^^^^^^\n",
425
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
426
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
427
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
428
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
429
+ " self._check_kernel_id(kernel_id)\n",
430
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
431
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
432
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 7bbdf51a-7ef3-4011-a075-14e70db1f6bf)\n",
433
+ "\u001b[33m[W 2025-06-20 15:37:40.120 ServerApp]\u001b[m 404 GET /api/kernels/7bbdf51a-7ef3-4011-a075-14e70db1f6bf?1750455460113 (e1bb6698e462478ab1b1bdda87374748@::1) 2.96ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_openai_gpt35_ready.ipynb?\n",
434
+ "\u001b[33m[W 2025-06-20 15:38:08.988 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
435
+ "\u001b[33m[W 2025-06-20 15:38:08.989 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa/channels?session_id=b956cf22-30ff-4115-a9c3-10439728645b (e1bb6698e462478ab1b1bdda87374748@::1) 1.60ms referer=None\n",
436
+ "\u001b[33m[W 2025-06-20 15:38:08.992 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455488990 (::1): Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa\n",
437
+ "\u001b[33m[W 2025-06-20 15:38:08.992 ServerApp]\u001b[m wrote error: 'Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa'\n",
438
+ " Traceback (most recent call last):\n",
439
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/tornado/web.py\", line 1786, in _execute\n",
440
+ " result = await result\n",
441
+ " ^^^^^^^^^^^^\n",
442
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/handlers.py\", line 75, in get\n",
443
+ " model = await ensure_async(km.kernel_model(kernel_id))\n",
444
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
445
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 500, in kernel_model\n",
446
+ " self._check_kernel_id(kernel_id)\n",
447
+ " File \"/opt/anaconda3/lib/python3.11/site-packages/jupyter_server/services/kernels/kernelmanager.py\", line 531, in _check_kernel_id\n",
448
+ " raise web.HTTPError(404, \"Kernel does not exist: %s\" % kernel_id)\n",
449
+ " tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: 506aad0a-4f83-4a48-b055-a123e7f186aa)\n",
450
+ "\u001b[33m[W 2025-06-20 15:38:08.992 ServerApp]\u001b[m 404 GET /api/kernels/506aad0a-4f83-4a48-b055-a123e7f186aa?1750455488990 (e1bb6698e462478ab1b1bdda87374748@::1) 1.43ms referer=http://localhost:8891/notebooks/Desktop/Proyectos_ImageMarker/POC-JuJitsu/rag_jujutsu_poc_joblib.ipynb?\n",
451
+ "^C\n",
452
+ "\u001b[32m[I 2025-06-20 15:39:52.966 ServerApp]\u001b[m interrupted\n",
453
+ "\u001b[32m[I 2025-06-20 15:39:52.966 ServerApp]\u001b[m Serving notebooks from local directory: /Users/ddiaz/Desktop/Proyectos_ImageMarker/JuJitsuPOC\n",
454
+ " 0 active kernels\n",
455
+ " Jupyter Server 2.10.0 is running at:\n",
456
+ " http://localhost:8891/tree?token=53dae3fcd0d912651e64cf45e29de3d9920a8fdccf3339e8\n",
457
+ " http://127.0.0.1:8891/tree?token=53dae3fcd0d912651e64cf45e29de3d9920a8fdccf3339e8\n",
458
+ "Shutdown this Jupyter server (y/[n])? \u001b[32m[I 2025-06-20 15:39:52.966 ServerApp]\u001b[m resuming operation...\n"
459
+ ]
460
+ }
461
+ ],
462
+ "source": [
463
+ "\n",
464
+ "!pip install --quiet openai langchain faiss-cpu PyPDF2 sentence-transformers joblib\n",
465
+ "!pip install ipywidgets==7.7.2\n",
466
+ "!jupyter nbextension enable --py widgetsnbextension\n",
467
+ "!jupyter notebook\n"
468
+ ]
469
+ },
470
+ {
471
+ "cell_type": "code",
472
+ "execution_count": 1,
473
+ "id": "49ee7721",
474
+ "metadata": {},
475
+ "outputs": [
476
+ {
477
+ "name": "stdout",
478
+ "output_type": "stream",
479
+ "text": [
480
+ "Loaded 329 chunks\n"
481
+ ]
482
+ }
483
+ ],
484
+ "source": [
485
+ "from PyPDF2 import PdfReader\n",
486
+ "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
487
+ "\n",
488
+ "def load_pdf_chunks(pdf_path):\n",
489
+ " reader = PdfReader(pdf_path)\n",
490
+ " raw_text = \"\"\n",
491
+ " for page in reader.pages:\n",
492
+ " raw_text += page.extract_text() + \"\\n\"\n",
493
+ "\n",
494
+ " splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)\n",
495
+ " return splitter.split_text(raw_text)\n",
496
+ "\n",
497
+ "chunks = load_pdf_chunks(\"JuJutsu-Contexto-Significado-Conexiones-Historia.pdf\")\n",
498
+ "print(f\"Loaded {len(chunks)} chunks\")\n"
499
+ ]
500
+ },
501
+ {
502
+ "cell_type": "code",
503
+ "execution_count": 3,
504
+ "id": "8109b626-0179-43e2-b924-65afe9af1e4e",
505
+ "metadata": {},
506
+ "outputs": [],
507
+ "source": [
508
+ "import openai"
509
+ ]
510
+ },
511
+ {
512
+ "cell_type": "code",
513
+ "execution_count": 5,
514
+ "id": "371c637e",
515
+ "metadata": {},
516
+ "outputs": [
517
+ {
518
+ "name": "stdout",
519
+ "output_type": "stream",
520
+ "text": [
521
+ "✅ Chunks and FAISS index serialized to rag_model.joblib\n"
522
+ ]
523
+ }
524
+ ],
525
+ "source": [
526
+ "import faiss\n",
527
+ "import numpy as np\n",
528
+ "import joblib\n",
529
+ "from openai import OpenAI\n",
530
+ "\n",
531
+ "import os\n",
532
+ "\n",
533
+ "import openai\n",
534
+ "from openai import OpenAI\n",
535
+ "os.environ[\"OPENAI_API_KEY\"] = \"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\"\n",
536
+ "\n",
537
+ "client = OpenAI()\n",
538
+ "# 2. Define embedding function\n",
539
+ "def get_openai_embeddings(texts, batch_size=20):\n",
540
+ " all_embeddings = []\n",
541
+ " for i in range(0, len(texts), batch_size):\n",
542
+ " batch = texts[i:i + batch_size]\n",
543
+ " try:\n",
544
+ " response = client.embeddings.create(\n",
545
+ " model=\"text-embedding-3-small\",\n",
546
+ " input=batch\n",
547
+ " )\n",
548
+ " batch_embeddings = [e.embedding for e in response.data]\n",
549
+ " all_embeddings.extend(batch_embeddings)\n",
550
+ " except Exception as e:\n",
551
+ " print(f\"⚠️ Failed on batch {i}-{i+batch_size}: {e}\")\n",
552
+ " return np.array(all_embeddings)\n",
553
+ "\n",
554
+ "# 3. Get embeddings from your loaded `chunks` (make sure chunks is defined)\n",
555
+ "embeddings = get_openai_embeddings(chunks)\n",
556
+ "\n",
557
+ "# 4. Build FAISS index\n",
558
+ "index = faiss.IndexFlatL2(embeddings.shape[1])\n",
559
+ "index.add(embeddings)\n",
560
+ "\n",
561
+ "# 5. Serialize chunks and index (no need to save model)\n",
562
+ "joblib.dump((chunks, index), \"rag_model.joblib\")\n",
563
+ "print(\"✅ Chunks and FAISS index serialized to rag_model.joblib\")\n"
564
+ ]
565
+ },
566
+ {
567
+ "cell_type": "code",
568
+ "execution_count": null,
569
+ "id": "28ce4963",
570
+ "metadata": {},
571
+ "outputs": [],
572
+ "source": [
573
+ "\n",
574
+ "import joblib\n",
575
+ "chunks, index = joblib.load(\"rag_model.joblib\")\n",
576
+ "print(\"Chunks and index loaded from rag_model.joblib\")\n"
577
+ ]
578
+ },
579
+ {
580
+ "cell_type": "code",
581
+ "execution_count": null,
582
+ "id": "51a89e77",
583
+ "metadata": {},
584
+ "outputs": [],
585
+ "source": [
586
+ "\n",
587
+ "def search(query, k=3):\n",
588
+ " response = openai.Embedding.create(\n",
589
+ " model=\"text-embedding-3-small\",\n",
590
+ " input=query\n",
591
+ " )\n",
592
+ " query_vec = np.array([response['data'][0]['embedding']])\n",
593
+ " scores, indices = index.search(query_vec, k)\n",
594
+ " return [chunks[i] for i in indices[0]]\n"
595
+ ]
596
+ },
597
+ {
598
+ "cell_type": "code",
599
+ "execution_count": null,
600
+ "id": "34315775",
601
+ "metadata": {},
602
+ "outputs": [],
603
+ "source": [
604
+ "\n",
605
+ "import os\n",
606
+ "import openai\n",
607
+ "from openai import OpenAI\n",
608
+ "\n",
609
+ "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\")\n",
610
+ "client = OpenAI()\n",
611
+ "\n",
612
+ "def chat_no_rag(question):\n",
613
+ " response = client.chat.completions.create(\n",
614
+ " model=\"gpt-3.5-turbo\",\n",
615
+ " messages=[\n",
616
+ " {\"role\": \"user\", \"content\": question}\n",
617
+ " ],\n",
618
+ " temperature=0.5,\n",
619
+ " max_tokens=200,\n",
620
+ " )\n",
621
+ " return response.choices[0].message.content\n",
622
+ "\n",
623
+ "def chat_with_rag(question, retrieved_chunks):\n",
624
+ " context = \"\\n\".join(retrieved_chunks)\n",
625
+ " prompt = f\"Usa el siguiente contexto para responder la pregunta:\\n\\n{context}\\n\\nPregunta: {question}\"\n",
626
+ "\n",
627
+ " response = client.chat.completions.create(\n",
628
+ " model=\"gpt-3.5-turbo\",\n",
629
+ " messages=[\n",
630
+ " {\"role\": \"user\", \"content\": prompt}\n",
631
+ " ],\n",
632
+ " temperature=0.3,\n",
633
+ " max_tokens=200,\n",
634
+ " )\n",
635
+ " return response.choices[0].message.content\n",
636
+ "\n",
637
+ "def chat_with_rag_enhanced(question, retrieved_chunks):\n",
638
+ " context = \"\\n\".join(retrieved_chunks)\n",
639
+ " prompt = (\n",
640
+ " \"Eres un experto en historia marcial. \"\n",
641
+ " \"Usa el siguiente contexto histórico para responder con precisión y detalle.\\n\\n\"\n",
642
+ " f\"Contexto:\\n{context}\\n\\n\"\n",
643
+ " f\"Pregunta: {question}\\nRespuesta:\"\n",
644
+ " )\n",
645
+ "\n",
646
+ " response = client.chat.completions.create(\n",
647
+ " model=\"gpt-3.5-turbo\",\n",
648
+ " messages=[\n",
649
+ " {\"role\": \"user\", \"content\": prompt}\n",
650
+ " ],\n",
651
+ " temperature=0.2,\n",
652
+ " max_tokens=200,\n",
653
+ " )\n",
654
+ " return response.choices[0].message.content\n"
655
+ ]
656
+ },
657
+ {
658
+ "cell_type": "code",
659
+ "execution_count": null,
660
+ "id": "900dfdfa",
661
+ "metadata": {},
662
+ "outputs": [],
663
+ "source": [
664
+ "\n",
665
+ "# Example query\n",
666
+ "query = \"¿Cuál es el origen del JuJutsu en Japón?\"\n",
667
+ "retrieved = search(query)\n",
668
+ "\n",
669
+ "print(\"🔹 Sin RAG:\")\n",
670
+ "print(chat_no_rag(query))\n",
671
+ "\n",
672
+ "print(\"\\n🔹 Con RAG:\")\n",
673
+ "print(chat_with_rag(query, retrieved))\n",
674
+ "\n",
675
+ "print(\"\\n🔹 Con RAG + Prompt mejorado:\")\n",
676
+ "print(chat_with_rag_enhanced(query, retrieved))\n"
677
+ ]
678
+ }
679
+ ],
680
+ "metadata": {
681
+ "kernelspec": {
682
+ "display_name": "Python 3 (ipykernel)",
683
+ "language": "python",
684
+ "name": "python3"
685
+ },
686
+ "language_info": {
687
+ "codemirror_mode": {
688
+ "name": "ipython",
689
+ "version": 3
690
+ },
691
+ "file_extension": ".py",
692
+ "mimetype": "text/x-python",
693
+ "name": "python",
694
+ "nbconvert_exporter": "python",
695
+ "pygments_lexer": "ipython3",
696
+ "version": "3.11.7"
697
+ }
698
+ },
699
+ "nbformat": 4,
700
+ "nbformat_minor": 5
701
+ }