Omar Solano
commited on
Commit
Β·
84bd9c0
1
Parent(s):
9e9355f
load .env variables for vscode debugging
Browse files
notebooks/03-RAG_with_LlamaIndex.ipynb
CHANGED
@@ -18,7 +18,7 @@
|
|
18 |
},
|
19 |
{
|
20 |
"cell_type": "code",
|
21 |
-
"execution_count":
|
22 |
"metadata": {
|
23 |
"colab": {
|
24 |
"base_uri": "https://localhost:8080/"
|
@@ -33,19 +33,27 @@
|
|
33 |
},
|
34 |
{
|
35 |
"cell_type": "code",
|
36 |
-
"execution_count":
|
37 |
"metadata": {
|
38 |
"id": "CWholrWlt2OQ"
|
39 |
},
|
40 |
"outputs": [],
|
41 |
"source": [
|
42 |
"import os\n",
|
|
|
43 |
"\n",
|
44 |
-
"
|
45 |
-
"
|
|
|
|
|
|
|
|
|
|
|
46 |
"\n",
|
47 |
"# Get your GOOGLE_API_KEY from https://aistudio.google.com/app/apikey\n",
|
48 |
-
"os.
|
|
|
|
|
49 |
]
|
50 |
},
|
51 |
{
|
@@ -77,7 +85,7 @@
|
|
77 |
},
|
78 |
{
|
79 |
"cell_type": "code",
|
80 |
-
"execution_count":
|
81 |
"metadata": {
|
82 |
"colab": {
|
83 |
"base_uri": "https://localhost:8080/"
|
@@ -92,7 +100,7 @@
|
|
92 |
"text": [
|
93 |
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
|
94 |
" Dload Upload Total Spent Left Speed\n",
|
95 |
-
"100 169k 100 169k 0 0
|
96 |
]
|
97 |
}
|
98 |
],
|
@@ -111,7 +119,7 @@
|
|
111 |
},
|
112 |
{
|
113 |
"cell_type": "code",
|
114 |
-
"execution_count":
|
115 |
"metadata": {
|
116 |
"colab": {
|
117 |
"base_uri": "https://localhost:8080/"
|
@@ -135,14 +143,16 @@
|
|
135 |
"\n",
|
136 |
"# Load the CSV file\n",
|
137 |
"with open(\"./mini-dataset.csv\", mode=\"r\", encoding=\"utf-8\") as file:\n",
|
138 |
-
"
|
139 |
"\n",
|
140 |
-
"
|
141 |
-
"
|
142 |
-
"
|
|
|
|
|
143 |
"\n",
|
144 |
"# The number of characters in the dataset.\n",
|
145 |
-
"print(
|
146 |
]
|
147 |
},
|
148 |
{
|
@@ -156,7 +166,7 @@
|
|
156 |
},
|
157 |
{
|
158 |
"cell_type": "code",
|
159 |
-
"execution_count":
|
160 |
"metadata": {
|
161 |
"id": "iXrr5-tnEfm9"
|
162 |
},
|
@@ -170,7 +180,7 @@
|
|
170 |
},
|
171 |
{
|
172 |
"cell_type": "code",
|
173 |
-
"execution_count":
|
174 |
"metadata": {
|
175 |
"colab": {
|
176 |
"base_uri": "https://localhost:8080/",
|
@@ -210,8 +220,10 @@
|
|
210 |
"text": [
|
211 |
"/Users/omar/Documents/ai_repos/ai-tutor-rag-system/env/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
212 |
" from .autonotebook import tqdm as notebook_tqdm\n",
|
213 |
-
"Parsing nodes: 100%|ββββββββββ| 14/14 [00:00<00:00,
|
214 |
-
"
|
|
|
|
|
215 |
]
|
216 |
}
|
217 |
],
|
@@ -241,7 +253,7 @@
|
|
241 |
},
|
242 |
{
|
243 |
"cell_type": "code",
|
244 |
-
"execution_count":
|
245 |
"metadata": {
|
246 |
"id": "bUaNH97dEfh9"
|
247 |
},
|
@@ -259,7 +271,7 @@
|
|
259 |
},
|
260 |
{
|
261 |
"cell_type": "code",
|
262 |
-
"execution_count":
|
263 |
"metadata": {
|
264 |
"colab": {
|
265 |
"base_uri": "https://localhost:8080/"
|
@@ -272,21 +284,19 @@
|
|
272 |
"name": "stdout",
|
273 |
"output_type": "stream",
|
274 |
"text": [
|
275 |
-
"LLaMA 2
|
276 |
"\n"
|
277 |
]
|
278 |
}
|
279 |
],
|
280 |
"source": [
|
281 |
-
"response = query_engine.query(\n",
|
282 |
-
" \"How many parameters LLaMA2 model has?\"\n",
|
283 |
-
")\n",
|
284 |
"print(response)"
|
285 |
]
|
286 |
},
|
287 |
{
|
288 |
"cell_type": "code",
|
289 |
-
"execution_count":
|
290 |
"metadata": {
|
291 |
"colab": {
|
292 |
"base_uri": "https://localhost:8080/"
|
@@ -299,15 +309,13 @@
|
|
299 |
"name": "stdout",
|
300 |
"output_type": "stream",
|
301 |
"text": [
|
302 |
-
"The context does not provide information about the release
|
303 |
"\n"
|
304 |
]
|
305 |
}
|
306 |
],
|
307 |
"source": [
|
308 |
-
"response = query_engine.query(\n",
|
309 |
-
" \"When will Llama3 will be released?\"\n",
|
310 |
-
")\n",
|
311 |
"print(response)"
|
312 |
]
|
313 |
}
|
|
|
18 |
},
|
19 |
{
|
20 |
"cell_type": "code",
|
21 |
+
"execution_count": null,
|
22 |
"metadata": {
|
23 |
"colab": {
|
24 |
"base_uri": "https://localhost:8080/"
|
|
|
33 |
},
|
34 |
{
|
35 |
"cell_type": "code",
|
36 |
+
"execution_count": 1,
|
37 |
"metadata": {
|
38 |
"id": "CWholrWlt2OQ"
|
39 |
},
|
40 |
"outputs": [],
|
41 |
"source": [
|
42 |
"import os\n",
|
43 |
+
"from dotenv import load_dotenv\n",
|
44 |
"\n",
|
45 |
+
"load_dotenv(\".env\")\n",
|
46 |
+
"\n",
|
47 |
+
"# Here we look for the OPENAI_API_KEY in the environment variables\n",
|
48 |
+
"OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\")\n",
|
49 |
+
"if not OPENAI_API_KEY:\n",
|
50 |
+
" # If it's not found, you can set it manually\n",
|
51 |
+
" os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\"\n",
|
52 |
"\n",
|
53 |
"# Get your GOOGLE_API_KEY from https://aistudio.google.com/app/apikey\n",
|
54 |
+
"GOOGLE_API_KEY = os.getenv(\"GOOGLE_API_KEY\")\n",
|
55 |
+
"if not GOOGLE_API_KEY:\n",
|
56 |
+
" os.environ[\"GOOGLE_API_KEY\"] = \"<YOUR_GOOGLE_KEY>\""
|
57 |
]
|
58 |
},
|
59 |
{
|
|
|
85 |
},
|
86 |
{
|
87 |
"cell_type": "code",
|
88 |
+
"execution_count": 2,
|
89 |
"metadata": {
|
90 |
"colab": {
|
91 |
"base_uri": "https://localhost:8080/"
|
|
|
100 |
"text": [
|
101 |
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
|
102 |
" Dload Upload Total Spent Left Speed\n",
|
103 |
+
"100 169k 100 169k 0 0 772k 0 --:--:-- --:--:-- --:--:-- 774k\n"
|
104 |
]
|
105 |
}
|
106 |
],
|
|
|
119 |
},
|
120 |
{
|
121 |
"cell_type": "code",
|
122 |
+
"execution_count": 3,
|
123 |
"metadata": {
|
124 |
"colab": {
|
125 |
"base_uri": "https://localhost:8080/"
|
|
|
143 |
"\n",
|
144 |
"# Load the CSV file\n",
|
145 |
"with open(\"./mini-dataset.csv\", mode=\"r\", encoding=\"utf-8\") as file:\n",
|
146 |
+
" csv_reader = csv.reader(file)\n",
|
147 |
"\n",
|
148 |
+
" for idx, row in enumerate(csv_reader):\n",
|
149 |
+
" if idx == 0:\n",
|
150 |
+
" continue\n",
|
151 |
+
" # Skip header row\n",
|
152 |
+
" rows.append(row)\n",
|
153 |
"\n",
|
154 |
"# The number of characters in the dataset.\n",
|
155 |
+
"print(\"number of articles:\", len(rows))"
|
156 |
]
|
157 |
},
|
158 |
{
|
|
|
166 |
},
|
167 |
{
|
168 |
"cell_type": "code",
|
169 |
+
"execution_count": 4,
|
170 |
"metadata": {
|
171 |
"id": "iXrr5-tnEfm9"
|
172 |
},
|
|
|
180 |
},
|
181 |
{
|
182 |
"cell_type": "code",
|
183 |
+
"execution_count": 5,
|
184 |
"metadata": {
|
185 |
"colab": {
|
186 |
"base_uri": "https://localhost:8080/",
|
|
|
220 |
"text": [
|
221 |
"/Users/omar/Documents/ai_repos/ai-tutor-rag-system/env/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
222 |
" from .autonotebook import tqdm as notebook_tqdm\n",
|
223 |
+
"Parsing nodes: 100%|ββββββββββ| 14/14 [00:00<00:00, 247.39it/s]\n",
|
224 |
+
"/Users/omar/Documents/ai_repos/ai-tutor-rag-system/env/lib/python3.12/site-packages/langchain/agents/json_chat/base.py:22: SyntaxWarning: invalid escape sequence '\\ '\n",
|
225 |
+
" \"\"\"Create an agent that uses JSON to format its logic, build for Chat Models.\n",
|
226 |
+
"Generating embeddings: 100%|ββββββββββ| 56/56 [00:01<00:00, 43.08it/s]\n"
|
227 |
]
|
228 |
}
|
229 |
],
|
|
|
253 |
},
|
254 |
{
|
255 |
"cell_type": "code",
|
256 |
+
"execution_count": 6,
|
257 |
"metadata": {
|
258 |
"id": "bUaNH97dEfh9"
|
259 |
},
|
|
|
271 |
},
|
272 |
{
|
273 |
"cell_type": "code",
|
274 |
+
"execution_count": 7,
|
275 |
"metadata": {
|
276 |
"colab": {
|
277 |
"base_uri": "https://localhost:8080/"
|
|
|
284 |
"name": "stdout",
|
285 |
"output_type": "stream",
|
286 |
"text": [
|
287 |
+
"LLaMA 2 comes in four different sizes: 7 billion, 13 billion, 34 billion, and 70 billion parameters. \n",
|
288 |
"\n"
|
289 |
]
|
290 |
}
|
291 |
],
|
292 |
"source": [
|
293 |
+
"response = query_engine.query(\"How many parameters LLaMA2 model has?\")\n",
|
|
|
|
|
294 |
"print(response)"
|
295 |
]
|
296 |
},
|
297 |
{
|
298 |
"cell_type": "code",
|
299 |
+
"execution_count": 8,
|
300 |
"metadata": {
|
301 |
"colab": {
|
302 |
"base_uri": "https://localhost:8080/"
|
|
|
309 |
"name": "stdout",
|
310 |
"output_type": "stream",
|
311 |
"text": [
|
312 |
+
"The context does not provide information about the release of Llama 3. \n",
|
313 |
"\n"
|
314 |
]
|
315 |
}
|
316 |
],
|
317 |
"source": [
|
318 |
+
"response = query_engine.query(\"When will Llama3 will be released?\")\n",
|
|
|
|
|
319 |
"print(response)"
|
320 |
]
|
321 |
}
|