Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -304,95 +304,42 @@ chain_neo4j = (
|
|
304 |
|
305 |
|
306 |
|
307 |
-
# def generate_answer(message, choice, retrieval_mode):
|
308 |
-
# logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
|
309 |
-
|
310 |
-
# # Check if the question is about hotels
|
311 |
-
# if "hotel" in message.lower() and "birmingham" in message.lower():
|
312 |
-
# response = fetch_google_hotels()
|
313 |
-
# return response, extract_addresses(response)
|
314 |
-
|
315 |
-
# # Check if the question is about restaurants
|
316 |
-
# if "restaurant" in message.lower() and "birmingham" in message.lower():
|
317 |
-
# response = fetch_yelp_restaurants()
|
318 |
-
# return response, extract_addresses(response)
|
319 |
-
# # Check if the question is about flights
|
320 |
-
# if "flight" in message.lower() and ("JFK" in message or "BHM" in message):
|
321 |
-
# response = fetch_google_flights()
|
322 |
-
# return response, extract_addresses(response)
|
323 |
-
|
324 |
-
# prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
325 |
-
|
326 |
-
# if retrieval_mode == "VDB":
|
327 |
-
# qa_chain = RetrievalQA.from_chain_type(
|
328 |
-
# llm=chat_model,
|
329 |
-
# chain_type="stuff",
|
330 |
-
# retriever=retriever,
|
331 |
-
# chain_type_kwargs={"prompt": prompt_template}
|
332 |
-
# )
|
333 |
-
# response = qa_chain({"query": message})
|
334 |
-
# logging.debug(f"Vector response: {response}")
|
335 |
-
# return response['result'], extract_addresses(response['result'])
|
336 |
-
# elif retrieval_mode == "KGF":
|
337 |
-
# response = chain_neo4j.invoke({"question": message})
|
338 |
-
# logging.debug(f"Knowledge-Graph response: {response}")
|
339 |
-
# return response, extract_addresses(response)
|
340 |
-
# else:
|
341 |
-
# return "Invalid retrieval mode selected.", []
|
342 |
-
|
343 |
def generate_answer(message, choice, retrieval_mode):
|
344 |
logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
|
345 |
|
346 |
-
|
347 |
-
response = ""
|
348 |
if "hotel" in message.lower() and "birmingham" in message.lower():
|
349 |
-
intro = "Here are the top Hotels in Birmingham:\n\n"
|
350 |
response = fetch_google_hotels()
|
351 |
-
|
352 |
-
|
|
|
|
|
353 |
response = fetch_yelp_restaurants()
|
354 |
-
|
355 |
-
|
|
|
356 |
response = fetch_google_flights()
|
357 |
-
|
358 |
-
prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
359 |
-
if retrieval_mode == "VDB":
|
360 |
-
qa_chain = RetrievalQA.from_chain_type(
|
361 |
-
llm=chat_model,
|
362 |
-
chain_type="stuff",
|
363 |
-
retriever=retriever,
|
364 |
-
chain_type_kwargs={"prompt": prompt_template}
|
365 |
-
)
|
366 |
-
response = qa_chain({"query": message})
|
367 |
-
logging.debug(f"Vector response: {response}")
|
368 |
-
response = response['result']
|
369 |
-
elif retrieval_mode == "KGF":
|
370 |
-
response = chain_neo4j.invoke({"question": message})
|
371 |
-
logging.debug(f"Knowledge-Graph response: {response}")
|
372 |
-
else:
|
373 |
-
response = "Invalid retrieval mode selected."
|
374 |
|
375 |
-
|
376 |
-
response_lines = response.splitlines()
|
377 |
-
formatted_response = ""
|
378 |
-
item_counter = 1
|
379 |
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
|
|
|
|
394 |
|
395 |
-
return intro + formatted_response.strip(), extract_addresses(response)
|
396 |
|
397 |
|
398 |
|
@@ -1143,10 +1090,10 @@ def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date="20
|
|
1143 |
|
1144 |
params = {
|
1145 |
"engine": "google_flights",
|
1146 |
-
"departure_id":
|
1147 |
-
"arrival_id":
|
1148 |
-
"outbound_date":
|
1149 |
-
"return_date":
|
1150 |
"currency": "USD",
|
1151 |
"hl": "en",
|
1152 |
"api_key": os.getenv("SERP_API") # Replace with your actual API key
|
|
|
304 |
|
305 |
|
306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
def generate_answer(message, choice, retrieval_mode):
|
308 |
logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
|
309 |
|
310 |
+
# Check if the question is about hotels
|
|
|
311 |
if "hotel" in message.lower() and "birmingham" in message.lower():
|
|
|
312 |
response = fetch_google_hotels()
|
313 |
+
return response, extract_addresses(response)
|
314 |
+
|
315 |
+
# Check if the question is about restaurants
|
316 |
+
if "restaurant" in message.lower() and "birmingham" in message.lower():
|
317 |
response = fetch_yelp_restaurants()
|
318 |
+
return response, extract_addresses(response)
|
319 |
+
# Check if the question is about flights
|
320 |
+
if "flight" in message.lower() and "birmingham" in message.lower():
|
321 |
response = fetch_google_flights()
|
322 |
+
return response, extract_addresses(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
323 |
|
324 |
+
prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
|
|
|
|
|
|
325 |
|
326 |
+
if retrieval_mode == "VDB":
|
327 |
+
qa_chain = RetrievalQA.from_chain_type(
|
328 |
+
llm=chat_model,
|
329 |
+
chain_type="stuff",
|
330 |
+
retriever=retriever,
|
331 |
+
chain_type_kwargs={"prompt": prompt_template}
|
332 |
+
)
|
333 |
+
response = qa_chain({"query": message})
|
334 |
+
logging.debug(f"Vector response: {response}")
|
335 |
+
return response['result'], extract_addresses(response['result'])
|
336 |
+
elif retrieval_mode == "KGF":
|
337 |
+
response = chain_neo4j.invoke({"question": message})
|
338 |
+
logging.debug(f"Knowledge-Graph response: {response}")
|
339 |
+
return response, extract_addresses(response)
|
340 |
+
else:
|
341 |
+
return "Invalid retrieval mode selected.", []
|
342 |
|
|
|
343 |
|
344 |
|
345 |
|
|
|
1090 |
|
1091 |
params = {
|
1092 |
"engine": "google_flights",
|
1093 |
+
"departure_id": departure_id,
|
1094 |
+
"arrival_id": arrival_id,
|
1095 |
+
"outbound_date": outbound_date,
|
1096 |
+
"return_date": return_date,
|
1097 |
"currency": "USD",
|
1098 |
"hl": "en",
|
1099 |
"api_key": os.getenv("SERP_API") # Replace with your actual API key
|