Pijush2023 commited on
Commit
f261cfc
·
verified ·
1 Parent(s): d717650

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -394,20 +394,23 @@ chain_neo4j = (
394
  phi_short_template = f"""
395
  As an expert on Birmingham, Alabama, I will provide concise, accurate, and informative responses to your queries. Given the sunny weather today, {current_date}, feel free to ask me anything you need to know about the city.
396
 
397
- - Brief details and facts
398
- - No unnecessary elaboration
399
- - Focus on relevance
400
 
401
  {{context}}
402
  Question: {{question}}
403
  Answer:
404
  """
405
 
406
- # Incorporate this template into the Phi-3.5 response generation section
 
 
 
 
 
407
  def generate_answer(message, choice, retrieval_mode, selected_model):
408
  logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
409
 
410
- try:
411
  if "hotel" in message.lower() or "hotels" in message.lower() and "birmingham" in message.lower():
412
  response = fetch_google_hotels()
413
  return response, extract_addresses(response)
@@ -453,7 +456,8 @@ def generate_answer(message, choice, retrieval_mode, selected_model):
453
  if response:
454
  generated_text = response[0]['generated_text']
455
  logging.debug(f"Phi-3.5 Response: {generated_text}")
456
- return generated_text, extract_addresses(generated_text)
 
457
  else:
458
  logging.error("Phi-3.5 did not return any response.")
459
  return "No response generated.", []
@@ -464,9 +468,10 @@ def generate_answer(message, choice, retrieval_mode, selected_model):
464
  else:
465
  return "Invalid retrieval mode selected.", []
466
 
467
- except Exception as e:
468
  logging.error(f"Error in generate_answer: {e}")
469
  return "Sorry, I encountered an error while processing your request.", []
 
470
 
471
 
472
 
 
394
  phi_short_template = f"""
395
  As an expert on Birmingham, Alabama, I will provide concise, accurate, and informative responses to your queries. Given the sunny weather today, {current_date}, feel free to ask me anything you need to know about the city.
396
 
397
+ Provide only the direct answer to the question without any follow-up questions.
 
 
398
 
399
  {{context}}
400
  Question: {{question}}
401
  Answer:
402
  """
403
 
404
+
405
+ def clean_response(response_text):
406
+ # Remove any unwanted follow-up questions or unnecessary text
407
+ cleaned_response = re.sub(r'Question:.*\nAnswer:', '', response_text, flags=re.DOTALL).strip()
408
+ return cleaned_response
409
+
410
  def generate_answer(message, choice, retrieval_mode, selected_model):
411
  logging.debug(f"generate_answer called with choice: {choice} and retrieval_mode: {retrieval_mode}")
412
 
413
+ try {
414
  if "hotel" in message.lower() or "hotels" in message.lower() and "birmingham" in message.lower():
415
  response = fetch_google_hotels()
416
  return response, extract_addresses(response)
 
456
  if response:
457
  generated_text = response[0]['generated_text']
458
  logging.debug(f"Phi-3.5 Response: {generated_text}")
459
+ cleaned_response = clean_response(generated_text)
460
+ return cleaned_response, extract_addresses(cleaned_response)
461
  else:
462
  logging.error("Phi-3.5 did not return any response.")
463
  return "No response generated.", []
 
468
  else:
469
  return "Invalid retrieval mode selected.", []
470
 
471
+ } catch (Exception e) {
472
  logging.error(f"Error in generate_answer: {e}")
473
  return "Sorry, I encountered an error while processing your request.", []
474
+ }
475
 
476
 
477