AlaFalaki commited on
Commit
519d431
β€’
1 Parent(s): 0e34496

Created using Colab

Browse files
notebooks/05-Improve_Prompts_+_Add_Source.ipynb CHANGED
@@ -21,18 +21,73 @@
21
  },
22
  {
23
  "cell_type": "code",
24
- "execution_count": null,
25
  "metadata": {
26
- "id": "QPJzr-I9XQ7l"
 
 
 
 
27
  },
28
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  "source": [
30
  "!pip install -q llama-index==0.10.9 openai==1.12.0 tiktoken==0.6.0 chromadb==0.4.22 llama-index-vector-stores-chroma==0.1.7"
31
  ]
32
  },
33
  {
34
  "cell_type": "code",
35
- "execution_count": null,
36
  "metadata": {
37
  "id": "riuXwpSPcvWC"
38
  },
@@ -41,12 +96,12 @@
41
  "import os\n",
42
  "\n",
43
  "# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
44
- "os.environ[\"OPENAI_API_KEY\"] = \"<YOUR_OPENAI_KEY>\"\n"
45
  ]
46
  },
47
  {
48
  "cell_type": "code",
49
- "execution_count": null,
50
  "metadata": {
51
  "id": "km-KQOrgr3VB"
52
  },
@@ -70,7 +125,7 @@
70
  },
71
  {
72
  "cell_type": "code",
73
- "execution_count": null,
74
  "metadata": {
75
  "id": "SQP87lHczHKc"
76
  },
@@ -86,7 +141,7 @@
86
  },
87
  {
88
  "cell_type": "code",
89
- "execution_count": null,
90
  "metadata": {
91
  "id": "zAaGcYMJzHAN"
92
  },
@@ -127,22 +182,22 @@
127
  },
128
  {
129
  "cell_type": "code",
130
- "execution_count": null,
131
  "metadata": {
132
  "colab": {
133
  "base_uri": "https://localhost:8080/"
134
  },
135
  "id": "fQtpDvUzKNzI",
136
- "outputId": "829f8e63-7767-43a1-b3c9-95ae099012e7"
137
  },
138
  "outputs": [
139
  {
140
- "name": "stdout",
141
  "output_type": "stream",
 
142
  "text": [
143
  " % Total % Received % Xferd Average Speed Time Time Time Current\n",
144
  " Dload Upload Total Spent Left Speed\n",
145
- "100 169k 100 169k 0 0 1044k 0 --:--:-- --:--:-- --:--:-- 1040k\n"
146
  ]
147
  }
148
  ],
@@ -161,24 +216,24 @@
161
  },
162
  {
163
  "cell_type": "code",
164
- "execution_count": null,
165
  "metadata": {
166
  "colab": {
167
  "base_uri": "https://localhost:8080/"
168
  },
169
  "id": "_WER5lt0N7c5",
170
- "outputId": "2e4eae71-fa3a-4faf-a4e2-d3efaeaa591a"
171
  },
172
  "outputs": [
173
  {
 
174
  "data": {
175
  "text/plain": [
176
  "14"
177
  ]
178
  },
179
- "execution_count": 7,
180
  "metadata": {},
181
- "output_type": "execute_result"
182
  }
183
  ],
184
  "source": [
@@ -209,7 +264,7 @@
209
  },
210
  {
211
  "cell_type": "code",
212
- "execution_count": null,
213
  "metadata": {
214
  "id": "lFvW_886dxKX"
215
  },
@@ -223,30 +278,58 @@
223
  },
224
  {
225
  "cell_type": "code",
226
- "execution_count": null,
227
  "metadata": {
228
  "colab": {
229
  "base_uri": "https://localhost:8080/"
230
  },
231
  "id": "Njoc3XEVkKkf",
232
- "outputId": "bab3878d-252d-4f9a-8a65-d2933e8dc891"
233
  },
234
  "outputs": [
235
  {
 
236
  "data": {
237
  "text/plain": [
238
  "14"
239
  ]
240
  },
241
- "execution_count": 9,
242
  "metadata": {},
243
- "output_type": "execute_result"
244
  }
245
  ],
246
  "source": [
247
  "len( documents )"
248
  ]
249
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  {
251
  "cell_type": "markdown",
252
  "metadata": {
 
21
  },
22
  {
23
  "cell_type": "code",
24
+ "execution_count": 1,
25
  "metadata": {
26
+ "colab": {
27
+ "base_uri": "https://localhost:8080/"
28
+ },
29
+ "id": "QPJzr-I9XQ7l",
30
+ "outputId": "33a73316-fbb0-4ec8-e0ef-5f534108bb83"
31
  },
32
+ "outputs": [
33
+ {
34
+ "output_type": "stream",
35
+ "name": "stdout",
36
+ "text": [
37
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m226.7/226.7 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
38
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m12.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
39
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m509.0/509.0 kB\u001b[0m \u001b[31m12.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
40
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m15.4/15.4 MB\u001b[0m \u001b[31m11.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
41
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m18.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
42
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
43
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m26.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
44
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m92.0/92.0 kB\u001b[0m \u001b[31m4.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
45
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.4/62.4 kB\u001b[0m \u001b[31m4.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
46
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.3/41.3 kB\u001b[0m \u001b[31m3.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
47
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.4/5.4 MB\u001b[0m \u001b[31m50.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
48
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.8/6.8 MB\u001b[0m \u001b[31m49.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
49
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m59.9/59.9 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
50
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m107.0/107.0 kB\u001b[0m \u001b[31m9.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
51
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.3/67.3 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
52
+ "\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
53
+ " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
54
+ " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
55
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m283.7/283.7 kB\u001b[0m \u001b[31m28.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
56
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━���━━━━\u001b[0m \u001b[32m1.6/1.6 MB\u001b[0m \u001b[31m64.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
57
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.6/67.6 kB\u001b[0m \u001b[31m7.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
58
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.9/71.9 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
59
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.6/53.6 kB\u001b[0m \u001b[31m4.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
60
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.5/142.5 kB\u001b[0m \u001b[31m16.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
61
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
62
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m6.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
63
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.9/141.9 kB\u001b[0m \u001b[31m14.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
64
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m290.4/290.4 kB\u001b[0m \u001b[31m27.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
65
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
66
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m52.5/52.5 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
67
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.5/130.5 kB\u001b[0m \u001b[31m14.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
68
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m341.4/341.4 kB\u001b[0m \u001b[31m29.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
69
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m48.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
70
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m61.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
71
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m130.2/130.2 kB\u001b[0m \u001b[31m15.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
72
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m307.7/307.7 kB\u001b[0m \u001b[31m32.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
73
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m47.2/47.2 kB\u001b[0m \u001b[31m5.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
74
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m11.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
75
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m6.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
76
+ "\u001b[?25h Building wheel for pypika (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
77
+ "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
78
+ "spacy 3.7.4 requires typer<0.10.0,>=0.3.0, but you have typer 0.12.3 which is incompatible.\n",
79
+ "weasel 0.3.4 requires typer<0.10.0,>=0.3.0, but you have typer 0.12.3 which is incompatible.\u001b[0m\u001b[31m\n",
80
+ "\u001b[0m"
81
+ ]
82
+ }
83
+ ],
84
  "source": [
85
  "!pip install -q llama-index==0.10.9 openai==1.12.0 tiktoken==0.6.0 chromadb==0.4.22 llama-index-vector-stores-chroma==0.1.7"
86
  ]
87
  },
88
  {
89
  "cell_type": "code",
90
+ "execution_count": 2,
91
  "metadata": {
92
  "id": "riuXwpSPcvWC"
93
  },
 
96
  "import os\n",
97
  "\n",
98
  "# Set the \"OPENAI_API_KEY\" in the Python environment. Will be used by OpenAI client later.\n",
99
+ "os.environ[\"OPENAI_API_KEY\"] = \"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\"\n"
100
  ]
101
  },
102
  {
103
  "cell_type": "code",
104
+ "execution_count": 3,
105
  "metadata": {
106
  "id": "km-KQOrgr3VB"
107
  },
 
125
  },
126
  {
127
  "cell_type": "code",
128
+ "execution_count": 4,
129
  "metadata": {
130
  "id": "SQP87lHczHKc"
131
  },
 
141
  },
142
  {
143
  "cell_type": "code",
144
+ "execution_count": 5,
145
  "metadata": {
146
  "id": "zAaGcYMJzHAN"
147
  },
 
182
  },
183
  {
184
  "cell_type": "code",
185
+ "execution_count": 6,
186
  "metadata": {
187
  "colab": {
188
  "base_uri": "https://localhost:8080/"
189
  },
190
  "id": "fQtpDvUzKNzI",
191
+ "outputId": "96a94167-ec27-4cf7-abc2-1017ad01afac"
192
  },
193
  "outputs": [
194
  {
 
195
  "output_type": "stream",
196
+ "name": "stdout",
197
  "text": [
198
  " % Total % Received % Xferd Average Speed Time Time Time Current\n",
199
  " Dload Upload Total Spent Left Speed\n",
200
+ "100 169k 100 169k 0 0 302k 0 --:--:-- --:--:-- --:--:-- 302k\n"
201
  ]
202
  }
203
  ],
 
216
  },
217
  {
218
  "cell_type": "code",
219
+ "execution_count": 7,
220
  "metadata": {
221
  "colab": {
222
  "base_uri": "https://localhost:8080/"
223
  },
224
  "id": "_WER5lt0N7c5",
225
+ "outputId": "fdf45169-f6c1-4e73-a476-3fb5e1adcd39"
226
  },
227
  "outputs": [
228
  {
229
+ "output_type": "execute_result",
230
  "data": {
231
  "text/plain": [
232
  "14"
233
  ]
234
  },
 
235
  "metadata": {},
236
+ "execution_count": 7
237
  }
238
  ],
239
  "source": [
 
264
  },
265
  {
266
  "cell_type": "code",
267
+ "execution_count": 8,
268
  "metadata": {
269
  "id": "lFvW_886dxKX"
270
  },
 
278
  },
279
  {
280
  "cell_type": "code",
281
+ "execution_count": 9,
282
  "metadata": {
283
  "colab": {
284
  "base_uri": "https://localhost:8080/"
285
  },
286
  "id": "Njoc3XEVkKkf",
287
+ "outputId": "5f270e74-465e-4252-e158-9a66e250cca4"
288
  },
289
  "outputs": [
290
  {
291
+ "output_type": "execute_result",
292
  "data": {
293
  "text/plain": [
294
  "14"
295
  ]
296
  },
 
297
  "metadata": {},
298
+ "execution_count": 9
299
  }
300
  ],
301
  "source": [
302
  "len( documents )"
303
  ]
304
  },
305
+ {
306
+ "cell_type": "code",
307
+ "source": [
308
+ "documents[0].metadata"
309
+ ],
310
+ "metadata": {
311
+ "id": "lKaZYB_IPr62",
312
+ "outputId": "4b7083a3-bde2-4f5f-ab76-a5b5074484a8",
313
+ "colab": {
314
+ "base_uri": "https://localhost:8080/"
315
+ }
316
+ },
317
+ "execution_count": 12,
318
+ "outputs": [
319
+ {
320
+ "output_type": "execute_result",
321
+ "data": {
322
+ "text/plain": [
323
+ "{'title': \"Beyond GPT-4: What's New?\",\n",
324
+ " 'url': 'https://pub.towardsai.net/beyond-gpt-4-whats-new-cbd61a448eb9#dda8',\n",
325
+ " 'source_name': 'towards_ai'}"
326
+ ]
327
+ },
328
+ "metadata": {},
329
+ "execution_count": 12
330
+ }
331
+ ]
332
+ },
333
  {
334
  "cell_type": "markdown",
335
  "metadata": {