wendru18 commited on
Commit
8c3c6c0
·
1 Parent(s): 7da8c71

getting closer to completion!

Browse files
Files changed (2) hide show
  1. README.md +3 -4
  2. main.ipynb +164 -116
README.md CHANGED
@@ -6,7 +6,6 @@ AskRedditGPT is a tool that takes in a query, sends it over to Reddit, and retur
6
 
7
  1. Take in query $q$ from user.
8
  2. Get $N$ topics from $q$ using GPT.
9
- 3. Determine $S$, which is a set of subreddits best-suited to answer $N$ topics.
10
- 4. Search $q \in S$.
11
- 5. Retrieve a set of segments that can answer $q$.
12
- 6. Summarise segments using GPT and return answer to user.
 
6
 
7
  1. Take in query $q$ from user.
8
  2. Get $N$ topics from $q$ using GPT.
9
+ 3. Determine $C$, which is a set of comments best-suited to answer $N$ topics.
10
+ 4. Search $q \in C$.
11
+ 5. Use GPT to return an answer to user.
 
main.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 94,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -18,7 +18,7 @@
18
  },
19
  {
20
  "cell_type": "code",
21
- "execution_count": 95,
22
  "metadata": {},
23
  "outputs": [],
24
  "source": [
@@ -29,12 +29,13 @@
29
  "from langchain.prompts import PromptTemplate\n",
30
  "from langchain.indexes.vectorstore import VectorstoreIndexCreator\n",
31
  "from langchain.chains.qa_with_sources import load_qa_with_sources_chain\n",
 
32
  "from langchain.llms import OpenAI"
33
  ]
34
  },
35
  {
36
  "cell_type": "code",
37
- "execution_count": 96,
38
  "metadata": {},
39
  "outputs": [],
40
  "source": [
@@ -45,6 +46,25 @@
45
  "reddit = praw.Reddit(client_id=REDDIT_CLIENT_ID, client_secret=REDDIT_CLIENT_SECRET, user_agent=REDDIT_USER_AGENT)"
46
  ]
47
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  {
49
  "attachments": {},
50
  "cell_type": "markdown",
@@ -55,14 +75,14 @@
55
  },
56
  {
57
  "cell_type": "code",
58
- "execution_count": 97,
59
  "metadata": {},
60
  "outputs": [],
61
  "source": [
62
  "def generate_topics(query, model=\"gpt-3.5-turbo\"):\n",
63
  "\n",
64
  " messages = [\n",
65
- " {\"role\": \"user\", \"content\": f\"Take this query '{query}' and return a list of 10 simple to understand topics (3 words or less) to input in Search so it returns good results.\"},\n",
66
  " ]\n",
67
  "\n",
68
  " response = openai.ChatCompletion.create(\n",
@@ -80,31 +100,37 @@
80
  },
81
  {
82
  "cell_type": "code",
83
- "execution_count": 108,
84
- "metadata": {},
85
- "outputs": [],
86
- "source": [
87
- "query = \"Are we in a recession right now?\""
88
- ]
89
- },
90
- {
91
- "cell_type": "code",
92
- "execution_count": 109,
93
  "metadata": {},
94
  "outputs": [
95
  {
96
- "name": "stdout",
97
- "output_type": "stream",
98
- "text": [
99
- "['Current economic status', 'Recession indicators', 'Unemployment rates', 'GDP growth rate', 'Consumer spending trends', 'Stock market performance', 'Federal Reserve actions', 'Economic stimulus packages', 'Business closures impact', 'Housing market trends']\n"
100
- ]
 
 
 
 
 
 
 
 
 
 
 
 
101
  }
102
  ],
103
  "source": [
104
  "topics = generate_topics(query)\n",
105
  "topics = [topic.strip() for topic in topics]\n",
106
  "topics = [topic[1:-1] if (topic.startswith('\"') and topic.endswith('\"')) or (topic.startswith(\"'\") and topic.endswith(\"'\")) else topic for topic in topics]\n",
107
- "print(topics)"
 
 
 
108
  ]
109
  },
110
  {
@@ -117,32 +143,37 @@
117
  },
118
  {
119
  "cell_type": "code",
120
- "execution_count": 110,
121
  "metadata": {},
122
  "outputs": [],
123
  "source": [
124
  "posts = []\n",
125
- "comments = []\n",
126
  "\n",
127
  "for topic in topics:\n",
128
  " for post in reddit.subreddit(\"all\").search(\n",
129
- " topic, limit=5):\n",
130
- " posts.append([post.id, post.title, post.subreddit, post.selftext])\n",
131
- " post.comments.replace_more(limit=1)\n",
132
  "\n",
 
 
 
133
  " for comment in post.comments.list():\n",
134
- " posts.append([post.id, post.title, post.subreddit, comment.body])\n",
135
  "\n",
136
- "posts = pd.DataFrame(posts,columns=['source', 'title', 'subreddit', 'text'])"
137
  ]
138
  },
139
  {
140
  "cell_type": "code",
141
- "execution_count": 111,
142
  "metadata": {},
143
  "outputs": [],
144
  "source": [
145
- "posts[\"subreddit\"] = posts[\"subreddit\"].apply(lambda x: x.display_name)\n"
 
 
 
 
 
146
  ]
147
  },
148
  {
@@ -155,158 +186,175 @@
155
  },
156
  {
157
  "cell_type": "code",
158
- "execution_count": 112,
159
  "metadata": {},
160
  "outputs": [],
161
  "source": [
162
- "text = posts[\"text\"].tolist()\n",
163
- "text = \" \".join(text)"
164
  ]
165
  },
166
  {
167
  "cell_type": "code",
168
- "execution_count": 113,
 
 
 
 
 
 
 
 
 
 
169
  "metadata": {},
170
  "outputs": [
171
  {
172
  "name": "stderr",
173
  "output_type": "stream",
174
  "text": [
175
- "Created a chunk of size 1635, which is longer than the specified 1000\n",
176
- "Created a chunk of size 1298, which is longer than the specified 1000\n",
177
- "Created a chunk of size 1109, which is longer than the specified 1000\n",
178
- "Created a chunk of size 2072, which is longer than the specified 1000\n",
179
- "Created a chunk of size 1498, which is longer than the specified 1000\n",
180
- "Created a chunk of size 1419, which is longer than the specified 1000\n",
181
- "Created a chunk of size 1127, which is longer than the specified 1000\n",
182
- "Created a chunk of size 1576, which is longer than the specified 1000\n",
183
- "Created a chunk of size 1314, which is longer than the specified 1000\n",
184
- "Created a chunk of size 2563, which is longer than the specified 1000\n",
185
- "Created a chunk of size 1287, which is longer than the specified 1000\n",
186
- "Created a chunk of size 1649, which is longer than the specified 1000\n",
187
- "Created a chunk of size 1616, which is longer than the specified 1000\n",
188
- "Created a chunk of size 1573, which is longer than the specified 1000\n",
189
- "Created a chunk of size 1024, which is longer than the specified 1000\n",
190
- "Created a chunk of size 1395, which is longer than the specified 1000\n",
191
- "Created a chunk of size 1712, which is longer than the specified 1000\n",
192
- "Created a chunk of size 1175, which is longer than the specified 1000\n",
193
- "Created a chunk of size 3872, which is longer than the specified 1000\n",
194
- "Created a chunk of size 1098, which is longer than the specified 1000\n",
195
- "Created a chunk of size 1429, which is longer than the specified 1000\n",
196
- "Created a chunk of size 1002, which is longer than the specified 1000\n",
197
- "Created a chunk of size 2241, which is longer than the specified 1000\n",
198
- "Created a chunk of size 1923, which is longer than the specified 1000\n",
199
- "Created a chunk of size 1716, which is longer than the specified 1000\n",
200
- "Created a chunk of size 2563, which is longer than the specified 1000\n",
201
- "Created a chunk of size 1221, which is longer than the specified 1000\n",
202
- "Created a chunk of size 2449, which is longer than the specified 1000\n",
203
- "Created a chunk of size 1321, which is longer than the specified 1000\n",
204
- "Created a chunk of size 1302, which is longer than the specified 1000\n",
205
- "Created a chunk of size 2182, which is longer than the specified 1000\n",
206
- "Created a chunk of size 1027, which is longer than the specified 1000\n",
207
- "Created a chunk of size 1156, which is longer than the specified 1000\n",
208
- "Created a chunk of size 7334, which is longer than the specified 1000\n",
209
- "Created a chunk of size 1849, which is longer than the specified 1000\n",
210
- "Created a chunk of size 2829, which is longer than the specified 1000\n",
211
- "Created a chunk of size 1567, which is longer than the specified 1000\n",
212
- "Created a chunk of size 1245, which is longer than the specified 1000\n",
213
- "Created a chunk of size 1299, which is longer than the specified 1000\n",
214
- "Created a chunk of size 1003, which is longer than the specified 1000\n",
215
- "Created a chunk of size 1327, which is longer than the specified 1000\n",
216
- "Created a chunk of size 2079, which is longer than the specified 1000\n",
217
- "Created a chunk of size 2780, which is longer than the specified 1000\n",
218
- "Created a chunk of size 1522, which is longer than the specified 1000\n",
219
- "Created a chunk of size 1766, which is longer than the specified 1000\n",
220
- "Created a chunk of size 1079, which is longer than the specified 1000\n",
221
- "Created a chunk of size 1080, which is longer than the specified 1000\n",
222
- "Created a chunk of size 1755, which is longer than the specified 1000\n",
223
- "Created a chunk of size 1232, which is longer than the specified 1000\n",
224
- "Created a chunk of size 1279, which is longer than the specified 1000\n",
225
- "Created a chunk of size 3189, which is longer than the specified 1000\n",
226
- "Created a chunk of size 1549, which is longer than the specified 1000\n",
227
- "Created a chunk of size 1124, which is longer than the specified 1000\n",
228
- "Created a chunk of size 1033, which is longer than the specified 1000\n",
229
- "Created a chunk of size 1676, which is longer than the specified 1000\n",
230
- "Created a chunk of size 1011, which is longer than the specified 1000\n",
231
- "Created a chunk of size 1723, which is longer than the specified 1000\n"
232
  ]
233
  }
234
  ],
235
  "source": [
236
- "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
237
- "texts = text_splitter.split_text(text)\n",
238
- "\n",
239
- "embeddings = OpenAIEmbeddings()"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  ]
241
  },
242
  {
243
  "cell_type": "code",
244
- "execution_count": 114,
 
 
 
 
 
 
 
 
 
 
245
  "metadata": {},
246
  "outputs": [
247
  {
248
- "name": "stderr",
249
- "output_type": "stream",
250
- "text": [
251
- "Using embedded DuckDB without persistence: data will be transient\n"
252
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  }
254
  ],
255
  "source": [
256
- "docsearch = Chroma.from_texts(texts, embeddings, metadatas=[{\"source\": str(i)} for i in range(len(texts))]).as_retriever()"
257
  ]
258
  },
259
  {
260
  "cell_type": "code",
261
- "execution_count": 115,
262
  "metadata": {},
263
  "outputs": [],
264
  "source": [
265
- "docs = docsearch.get_relevant_documents(query)"
 
 
266
  ]
267
  },
268
  {
269
  "cell_type": "code",
270
- "execution_count": 116,
271
  "metadata": {},
272
  "outputs": [
273
  {
274
  "data": {
275
  "text/plain": [
276
- "[Document(page_content=\"A recession is always just around the corner, meanwhile the S&P has been making higher lows since October 2022, unemployed in Canada is 5.0%, and GDP hasn’t been negative for two quarters. It is likely to happen. And economists will have to work fast to figure out a solution. You need demand to sustain supply. And without jobs there isn't demand, nor tax revenue.\\n\\nSo short term: pain is possible.\\n\\nMedium term: we might benefit from doing less work and getting paid the same.\", metadata={'source': '39'}),\n",
277
- " Document(page_content=\"Don't listen to people who say GDP is the only thing that matters for recessions. The NBER's definition -- which hasn't changed -- requires economic downturn across the economy in a broad sense. We probably can't have a recession and very low unemployment at the same time. So if we have a recession, we will have layoffs, too. [deleted] Most layoffs I've seen headlines for are in tech. While tech is a huge sector, it is important to look at the market as a whole. Job growth and job demand is still high. There are many many different indicators people look at. Housing prices is another. The difference between the bond curve. 3 month compared to the 1 year is another common one. When that inverts it means the economy isn't in a great place. It's so hard to predict which is why people constantly say to dollar cost average. Continuously buy and don't try to time anything. This time unemployment rate will be affected.\", metadata={'source': '13'}),\n",
278
- " Document(page_content='High tech layoffs often triggers layoff in retail as affected people no longer have the means to spend. Restaurant closing. Meta has to write off $0.67 billion dollars or more next qtr as 1 time charge. Tweeter let go 50 pct employees so SF is already slow business wise. Housing industry is going to get hit this winter and even spring. Be honest with ourselves we have been in recession most of the year. Not too many mfg jobs are in the US so you do not see that many job losses.\\n\\nAfter Xmas I imagine companies like mail order delivery will slow down also. Your pocketbook. Negative GDP, inflation, decrease in purchases, growing unemployment... decrease of consumer spending; and increase of umemployment Honestly fear of a recession is the best indicator. People and companies start holding their money close to be safe and it becomes a self fulfilling prophecy. Most reliable indicator is when people are yelling for higher prices when their asset already doubled, tripled in value.', metadata={'source': '14'}),\n",
279
- " Document(page_content='?? Agreed. Investors are jumping at the slightest bit of good news. But the job market is still strong, Fed wont stop raising rates until that changes. Not to mention the fact that oil is going up again. Which was a big factor in how we got to 8% - 9% inflation in the first place. Gas is almost $6 in my area now. More than it has ever been where I live. We are at the beginning of a lot of pain. Not the middle or the end. Recession is here, and it will deepen and broaden until everyone finally sees it. I mean australia raised under expectations but I dont think that matter I think the jump was - Australia only bumped by 25 basis pts and for some reason the market is in love with the fed pivot idea, jobs openings reduced something like 10%, Bond yields went down as well. But no, nothing fundamentally changed. The bank of England has started QE >didn\\'t interest rates hike again?\\n\\nYou \"call a trap\" but aren\\'t entirely sure if interest rates were hiked (they were)?', metadata={'source': '179'})]"
280
  ]
281
  },
282
- "execution_count": 116,
283
  "metadata": {},
284
  "output_type": "execute_result"
285
  }
286
  ],
287
  "source": [
288
- "docs"
289
  ]
290
  },
291
  {
292
  "cell_type": "code",
293
- "execution_count": 117,
294
  "metadata": {},
295
  "outputs": [
296
  {
297
  "data": {
298
  "text/plain": [
299
- "' It is likely that we are in a recession right now.\\nSOURCES: 39, 13, 14, 179'"
 
 
 
 
 
 
 
 
 
300
  ]
301
  },
302
- "execution_count": 117,
303
  "metadata": {},
304
  "output_type": "execute_result"
305
  }
306
  ],
307
  "source": [
308
- "chain = load_qa_with_sources_chain(OpenAI(temperature=0), chain_type=\"stuff\")\n",
309
- "chain.run(input_documents=docs, question=query)"
310
  ]
311
  }
312
  ],
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 258,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
18
  },
19
  {
20
  "cell_type": "code",
21
+ "execution_count": 259,
22
  "metadata": {},
23
  "outputs": [],
24
  "source": [
 
29
  "from langchain.prompts import PromptTemplate\n",
30
  "from langchain.indexes.vectorstore import VectorstoreIndexCreator\n",
31
  "from langchain.chains.qa_with_sources import load_qa_with_sources_chain\n",
32
+ "from langchain.chains import ConversationalRetrievalChain\n",
33
  "from langchain.llms import OpenAI"
34
  ]
35
  },
36
  {
37
  "cell_type": "code",
38
+ "execution_count": 260,
39
  "metadata": {},
40
  "outputs": [],
41
  "source": [
 
46
  "reddit = praw.Reddit(client_id=REDDIT_CLIENT_ID, client_secret=REDDIT_CLIENT_SECRET, user_agent=REDDIT_USER_AGENT)"
47
  ]
48
  },
49
+ {
50
+ "attachments": {},
51
+ "cell_type": "markdown",
52
+ "metadata": {},
53
+ "source": [
54
+ "## Query"
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": 261,
60
+ "metadata": {},
61
+ "outputs": [],
62
+ "source": [
63
+ "query = '''\n",
64
+ "Where can I find a good gluten-free pizza in Stockholm?\n",
65
+ "'''"
66
+ ]
67
+ },
68
  {
69
  "attachments": {},
70
  "cell_type": "markdown",
 
75
  },
76
  {
77
  "cell_type": "code",
78
+ "execution_count": 262,
79
  "metadata": {},
80
  "outputs": [],
81
  "source": [
82
  "def generate_topics(query, model=\"gpt-3.5-turbo\"):\n",
83
  "\n",
84
  " messages = [\n",
85
+ " {\"role\": \"user\", \"content\": f\"Take this query '{query}' and return a list of 10 simple to understand topics (4 words or less) to input in Search so it returns good results.\"},\n",
86
  " ]\n",
87
  "\n",
88
  " response = openai.ChatCompletion.create(\n",
 
100
  },
101
  {
102
  "cell_type": "code",
103
+ "execution_count": 263,
 
 
 
 
 
 
 
 
 
104
  "metadata": {},
105
  "outputs": [
106
  {
107
+ "data": {
108
+ "text/plain": [
109
+ "['Gluten free pizza Stockholm',\n",
110
+ " 'Best gluten free pizza',\n",
111
+ " 'Pizza without gluten',\n",
112
+ " 'Stockholm pizza options',\n",
113
+ " 'Gluten free restaurants Stockholm',\n",
114
+ " 'Pizza delivery gluten free',\n",
115
+ " 'Stockholm pizza places',\n",
116
+ " 'Gluten free pizza toppings',\n",
117
+ " 'Pizza crust gluten free',\n",
118
+ " 'Vegan gluten free pizza']"
119
+ ]
120
+ },
121
+ "execution_count": 263,
122
+ "metadata": {},
123
+ "output_type": "execute_result"
124
  }
125
  ],
126
  "source": [
127
  "topics = generate_topics(query)\n",
128
  "topics = [topic.strip() for topic in topics]\n",
129
  "topics = [topic[1:-1] if (topic.startswith('\"') and topic.endswith('\"')) or (topic.startswith(\"'\") and topic.endswith(\"'\")) else topic for topic in topics]\n",
130
+ "\n",
131
+ "topics = [re.sub(r'[^a-zA-Z0-9\\s]', ' ', topic) for topic in topics]\n",
132
+ "\n",
133
+ "topics"
134
  ]
135
  },
136
  {
 
143
  },
144
  {
145
  "cell_type": "code",
146
+ "execution_count": 264,
147
  "metadata": {},
148
  "outputs": [],
149
  "source": [
150
  "posts = []\n",
 
151
  "\n",
152
  "for topic in topics:\n",
153
  " for post in reddit.subreddit(\"all\").search(\n",
154
+ " topic, limit=10):\n",
 
 
155
  "\n",
156
+ " post.comments.replace_more(limit=3)\n",
157
+ "\n",
158
+ " # TODO: A check can be added here once we have enough comments for a post. This should drastically reduce the number of requests to the API and time spent.\n",
159
  " for comment in post.comments.list():\n",
160
+ " posts.append([comment.id, post.id, post.title, post.author, comment.body])\n",
161
  "\n",
162
+ "posts = pd.DataFrame(posts,columns=['source', 'post_id', 'title', 'author', 'text'])"
163
  ]
164
  },
165
  {
166
  "cell_type": "code",
167
+ "execution_count": 265,
168
  "metadata": {},
169
  "outputs": [],
170
  "source": [
171
+ "# Drop empty texts or [\"deleted\"] texts\n",
172
+ "posts = posts[posts['text'].str.len() > 0]\n",
173
+ "posts = posts[posts['text'] != \"[deleted]\"]\n",
174
+ "\n",
175
+ "# Drop duplicate ids\n",
176
+ "posts = posts.drop_duplicates(subset=['source'])"
177
  ]
178
  },
179
  {
 
186
  },
187
  {
188
  "cell_type": "code",
189
+ "execution_count": 266,
190
  "metadata": {},
191
  "outputs": [],
192
  "source": [
193
+ "posts = posts.to_dict('records')"
 
194
  ]
195
  },
196
  {
197
  "cell_type": "code",
198
+ "execution_count": 267,
199
+ "metadata": {},
200
+ "outputs": [],
201
+ "source": [
202
+ "# Convert posts[\"text\"] to a list of strings\n",
203
+ "texts = [post[\"title\"] + \" \" + post[\"text\"] for post in posts]"
204
+ ]
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "execution_count": 268,
209
  "metadata": {},
210
  "outputs": [
211
  {
212
  "name": "stderr",
213
  "output_type": "stream",
214
  "text": [
215
+ "WARNING:chromadb:Using embedded DuckDB without persistence: data will be transient\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  ]
217
  }
218
  ],
219
  "source": [
220
+ "db = Chroma.from_texts(texts, OpenAIEmbeddings(), metadatas=[{\"source\": post[\"source\"], \"post_id\": post[\"post_id\"], \"author\": post[\"author\"].name} for post in posts])"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "code",
225
+ "execution_count": 269,
226
+ "metadata": {},
227
+ "outputs": [],
228
+ "source": [
229
+ "retriever = db.as_retriever(search_type=\"similarity\", search_kwargs={\"k\": 10})"
230
+ ]
231
+ },
232
+ {
233
+ "cell_type": "code",
234
+ "execution_count": 270,
235
+ "metadata": {},
236
+ "outputs": [],
237
+ "source": [
238
+ "qa = ConversationalRetrievalChain.from_llm(OpenAI(temperature=0), retriever, return_source_documents=True)"
239
  ]
240
  },
241
  {
242
  "cell_type": "code",
243
+ "execution_count": 291,
244
+ "metadata": {},
245
+ "outputs": [],
246
+ "source": [
247
+ "chat_history = []\n",
248
+ "result = qa({\"question\": query, \"chat_history\": chat_history})"
249
+ ]
250
+ },
251
+ {
252
+ "cell_type": "code",
253
+ "execution_count": 292,
254
  "metadata": {},
255
  "outputs": [
256
  {
257
+ "data": {
258
+ "text/plain": [
259
+ "' Meno Male. Super nice Napoletana style Italian pizza, they have a few restaurants throughout Stockholm.'"
260
+ ]
261
+ },
262
+ "execution_count": 292,
263
+ "metadata": {},
264
+ "output_type": "execute_result"
265
+ }
266
+ ],
267
+ "source": [
268
+ "result[\"answer\"]"
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "code",
273
+ "execution_count": 293,
274
+ "metadata": {},
275
+ "outputs": [
276
+ {
277
+ "data": {
278
+ "text/plain": [
279
+ "[Document(page_content='Gluten free pizza in Stockholm? Any pizzeria', metadata={'source': 'irirsw2', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
280
+ " Document(page_content='Gluten free pizza in Stockholm? Crispy pizza', metadata={'source': 'iritand', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
281
+ " Document(page_content='Gluten free pizza in Stockholm? Thanks!', metadata={'source': 'irimidh', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
282
+ " Document(page_content='Var kan jag köpa glutenfri kebab pizza?? (Stockholm) Quick search:\\n\\n[https://www.findmeglutenfree.com/se/stockholm/pizza](https://www.findmeglutenfree.com/se/stockholm/pizza)', metadata={'source': 'jef789l', 'post_id': '127mh90', 'author': 'TheRoyalStork'}),\n",
283
+ " Document(page_content='Var kan jag köpa glutenfri kebab pizza?? (Stockholm) Tack!', metadata={'source': 'jeg12d4', 'post_id': '127mh90', 'author': 'TheRoyalStork'}),\n",
284
+ " Document(page_content='Gluten free pizza in Stockholm? Most places have gluten free pizza. Only Giro and Meno Male have good gluten free pizza.', metadata={'source': 'irm0583', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
285
+ " Document(page_content='Gluten free pizza in Stockholm? Meno Male. Super nice Napoletana style Italian pizza, they have a few restaurants throughout Stockholm', metadata={'source': 'irilvan', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
286
+ " Document(page_content='Gluten free pizza in Stockholm? Stockholm is like the capital of gluten intolerance so I think you will be fine in most (central) places', metadata={'source': 'irioh1a', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
287
+ " Document(page_content='Gluten free pizza in Stockholm? This is the right answer. Gluten-avoidants that I know like menomale.', metadata={'source': 'irjufjn', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
288
+ " Document(page_content='Var kan jag köpa glutenfri kebab pizza?? (Stockholm) A lot of pizza places offer this if you ask for it. Check with your local pizza place and you might be lucky. Usually boring prefab bread tho.', metadata={'source': 'jef91ea', 'post_id': '127mh90', 'author': 'TheRoyalStork'})]"
289
+ ]
290
+ },
291
+ "execution_count": 293,
292
+ "metadata": {},
293
+ "output_type": "execute_result"
294
  }
295
  ],
296
  "source": [
297
+ "result[\"source_documents\"]"
298
  ]
299
  },
300
  {
301
  "cell_type": "code",
302
+ "execution_count": 297,
303
  "metadata": {},
304
  "outputs": [],
305
  "source": [
306
+ "new_query = \"Are most pizzas in Stockholm gluten-free?\"\n",
307
+ "\n",
308
+ "new_result = qa({\"question\": query + new_query, \"chat_history\": result[\"chat_history\"]})"
309
  ]
310
  },
311
  {
312
  "cell_type": "code",
313
+ "execution_count": 298,
314
  "metadata": {},
315
  "outputs": [
316
  {
317
  "data": {
318
  "text/plain": [
319
+ "' Most places have gluten free pizza. Only Giro and Meno Male have good gluten free pizza. Pretty much all pizzerias serve GF pizza, but most use store-bought pizza bases. Stockholm is like the capital of gluten intolerance so I think you will be fine in most (central) places. Meno Male is a great option for Napoletana style Italian pizza, they have a few restaurants throughout Stockholm.'"
 
 
 
320
  ]
321
  },
322
+ "execution_count": 298,
323
  "metadata": {},
324
  "output_type": "execute_result"
325
  }
326
  ],
327
  "source": [
328
+ "new_result[\"answer\"]"
329
  ]
330
  },
331
  {
332
  "cell_type": "code",
333
+ "execution_count": 299,
334
  "metadata": {},
335
  "outputs": [
336
  {
337
  "data": {
338
  "text/plain": [
339
+ "[Document(page_content='Gluten free pizza in Stockholm? Any pizzeria', metadata={'source': 'irirsw2', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
340
+ " Document(page_content='Gluten free pizza in Stockholm? Thanks!', metadata={'source': 'irimidh', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
341
+ " Document(page_content='Gluten free pizza in Stockholm? Crispy pizza', metadata={'source': 'iritand', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
342
+ " Document(page_content='Gluten free pizza in Stockholm? Most places have gluten free pizza. Only Giro and Meno Male have good gluten free pizza.', metadata={'source': 'irm0583', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
343
+ " Document(page_content='Var kan jag köpa glutenfri kebab pizza?? (Stockholm) Quick search:\\n\\n[https://www.findmeglutenfree.com/se/stockholm/pizza](https://www.findmeglutenfree.com/se/stockholm/pizza)', metadata={'source': 'jef789l', 'post_id': '127mh90', 'author': 'TheRoyalStork'}),\n",
344
+ " Document(page_content='Var kan jag köpa glutenfri kebab pizza?? (Stockholm) Tack!', metadata={'source': 'jeg12d4', 'post_id': '127mh90', 'author': 'TheRoyalStork'}),\n",
345
+ " Document(page_content='Gluten free pizza in Stockholm? Pretty much all pizzerias serve GF pizza, but most use store-bought pizza bases.', metadata={'source': 'irjap32', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
346
+ " Document(page_content='Gluten free pizza in Stockholm? Stockholm is like the capital of gluten intolerance so I think you will be fine in most (central) places', metadata={'source': 'irioh1a', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
347
+ " Document(page_content='Gluten free pizza in Stockholm? Meno Male. Super nice Napoletana style Italian pizza, they have a few restaurants throughout Stockholm', metadata={'source': 'irilvan', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'}),\n",
348
+ " Document(page_content='Gluten free pizza in Stockholm? Has anyone here with a gluten intolerance diagnosis eaten a gf pizza from a pizzeria? Was it without issues? I imagine that all the flour handling, the oven and the spade would contaminate any gf pizza with gluten.', metadata={'source': 'irjmdif', 'post_id': 'xyti59', 'author': 'Head-Commission-8222'})]"
349
  ]
350
  },
351
+ "execution_count": 299,
352
  "metadata": {},
353
  "output_type": "execute_result"
354
  }
355
  ],
356
  "source": [
357
+ "new_result[\"source_documents\"]"
 
358
  ]
359
  }
360
  ],