Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -418,20 +418,24 @@ def generate_answer(message, choice, retrieval_mode, selected_model):
|
|
418 |
logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
|
419 |
|
420 |
try:
|
|
|
421 |
if "hotel" in message.lower() or "hotels" in message.lower() and "birmingham" in message.lower():
|
422 |
response = fetch_google_hotels()
|
423 |
return response, extract_addresses(response)
|
424 |
|
|
|
425 |
if "restaurant" in message.lower() or "restaurants" in message.lower() and "birmingham" in message.lower():
|
426 |
response = fetch_yelp_restaurants()
|
427 |
return response, extract_addresses(response)
|
428 |
|
|
|
429 |
if "flight" in message.lower() or "flights" in message.lower() and "birmingham" in message.lower():
|
430 |
response = fetch_google_flights()
|
431 |
return response, extract_addresses(response)
|
432 |
|
433 |
if retrieval_mode == "VDB":
|
434 |
if selected_model == chat_model:
|
|
|
435 |
retriever = gpt_retriever
|
436 |
prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
437 |
context = retriever.get_relevant_documents(message)
|
@@ -447,25 +451,28 @@ def generate_answer(message, choice, retrieval_mode, selected_model):
|
|
447 |
return response['result'], extract_addresses(response['result'])
|
448 |
|
449 |
elif selected_model == phi_pipe:
|
|
|
450 |
retriever = phi_retriever
|
451 |
context = retriever.get_relevant_documents(message)
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
|
|
456 |
|
457 |
-
|
458 |
-
|
|
|
|
|
459 |
"return_full_text": False,
|
460 |
-
"temperature": 0.
|
461 |
-
"do_sample":
|
462 |
})
|
463 |
|
464 |
if response:
|
465 |
generated_text = response[0]['generated_text']
|
466 |
logging.debug(f"Phi-3.5 Response: {generated_text}")
|
467 |
-
|
468 |
-
return cleaned_response, extract_addresses(cleaned_response)
|
469 |
else:
|
470 |
logging.error("Phi-3.5 did not return any response.")
|
471 |
return "No response generated.", []
|
@@ -486,7 +493,6 @@ def generate_answer(message, choice, retrieval_mode, selected_model):
|
|
486 |
|
487 |
|
488 |
|
489 |
-
|
490 |
def bot(history, choice, tts_choice, retrieval_mode, model_choice):
|
491 |
if not history:
|
492 |
return history
|
|
|
418 |
logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
|
419 |
|
420 |
try:
|
421 |
+
# Handle hotel-related queries
|
422 |
if "hotel" in message.lower() or "hotels" in message.lower() and "birmingham" in message.lower():
|
423 |
response = fetch_google_hotels()
|
424 |
return response, extract_addresses(response)
|
425 |
|
426 |
+
# Handle restaurant-related queries
|
427 |
if "restaurant" in message.lower() or "restaurants" in message.lower() and "birmingham" in message.lower():
|
428 |
response = fetch_yelp_restaurants()
|
429 |
return response, extract_addresses(response)
|
430 |
|
431 |
+
# Handle flight-related queries
|
432 |
if "flight" in message.lower() or "flights" in message.lower() and "birmingham" in message.lower():
|
433 |
response = fetch_google_flights()
|
434 |
return response, extract_addresses(response)
|
435 |
|
436 |
if retrieval_mode == "VDB":
|
437 |
if selected_model == chat_model:
|
438 |
+
# Use GPT-4o with its vector store and template
|
439 |
retriever = gpt_retriever
|
440 |
prompt_template = QA_CHAIN_PROMPT_1 if choice == "Details" else QA_CHAIN_PROMPT_2
|
441 |
context = retriever.get_relevant_documents(message)
|
|
|
451 |
return response['result'], extract_addresses(response['result'])
|
452 |
|
453 |
elif selected_model == phi_pipe:
|
454 |
+
# Use Phi-3.5 with its vector store and a simplified prompt
|
455 |
retriever = phi_retriever
|
456 |
context = retriever.get_relevant_documents(message)
|
457 |
+
prompt = f"""
|
458 |
+
Here is the information :
|
459 |
+
{context}
|
460 |
+
{message}
|
461 |
+
"""
|
462 |
|
463 |
+
logging.debug(f"Phi-3.5 Prompt: {prompt}")
|
464 |
+
|
465 |
+
response = selected_model(prompt, **{
|
466 |
+
"max_new_tokens": 128,
|
467 |
"return_full_text": False,
|
468 |
+
"temperature": 0.5,
|
469 |
+
"do_sample": False,
|
470 |
})
|
471 |
|
472 |
if response:
|
473 |
generated_text = response[0]['generated_text']
|
474 |
logging.debug(f"Phi-3.5 Response: {generated_text}")
|
475 |
+
return generated_text, extract_addresses(generated_text)
|
|
|
476 |
else:
|
477 |
logging.error("Phi-3.5 did not return any response.")
|
478 |
return "No response generated.", []
|
|
|
493 |
|
494 |
|
495 |
|
|
|
496 |
def bot(history, choice, tts_choice, retrieval_mode, model_choice):
|
497 |
if not history:
|
498 |
return history
|