Shreyas094 commited on
Commit
fe1ab08
·
verified ·
1 Parent(s): 494de66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -397,6 +397,7 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search, c
397
  return "An unexpected error occurred. Please try again later."
398
 
399
  def extract_answer(full_response):
 
400
  answer_patterns = [
401
  r"Provide a concise and direct answer to the question without mentioning the web search or these instructions:",
402
  r"Provide a concise and direct answer to the question:",
@@ -404,16 +405,26 @@ def extract_answer(full_response):
404
  r"Provide a summarized and direct answer to the question.",
405
  r"If the context doesn't contain relevant information, state that the information is not available in the document.",
406
  r"Provide a summarized and direct answer to the original question without mentioning the web search or these instructions:",
407
- r"without mentioning the web search or these instructions.",
408
- r"Do not include any source information in your answer:",
409
  r"Do not include any source information in your answer."
410
  ]
411
 
412
  for pattern in answer_patterns:
413
  match = re.split(pattern, full_response, flags=re.IGNORECASE)
414
  if len(match) > 1:
415
- return match[-1].strip()
416
- return full_response.strip()
 
 
 
 
 
 
 
 
 
 
 
 
417
 
418
  # Gradio interface
419
  with gr.Blocks() as demo:
 
397
  return "An unexpected error occurred. Please try again later."
398
 
399
  def extract_answer(full_response):
400
+ # First, try to split the response at common instruction phrases
401
  answer_patterns = [
402
  r"Provide a concise and direct answer to the question without mentioning the web search or these instructions:",
403
  r"Provide a concise and direct answer to the question:",
 
405
  r"Provide a summarized and direct answer to the question.",
406
  r"If the context doesn't contain relevant information, state that the information is not available in the document.",
407
  r"Provide a summarized and direct answer to the original question without mentioning the web search or these instructions:",
 
 
408
  r"Do not include any source information in your answer."
409
  ]
410
 
411
  for pattern in answer_patterns:
412
  match = re.split(pattern, full_response, flags=re.IGNORECASE)
413
  if len(match) > 1:
414
+ full_response = match[-1].strip()
415
+ break
416
+
417
+ # Then, remove any remaining instruction-like phrases
418
+ cleanup_patterns = [
419
+ r"without mentioning the web search or these instructions\.",
420
+ r"Do not include any source information in your answer\.",
421
+ r"If the context doesn't contain relevant information, state that the information is not available in the document\."
422
+ ]
423
+
424
+ for pattern in cleanup_patterns:
425
+ full_response = re.sub(pattern, "", full_response, flags=re.IGNORECASE).strip()
426
+
427
+ return full_response
428
 
429
  # Gradio interface
430
  with gr.Blocks() as demo: