Shreyas094 commited on
Commit
07bfb82
·
verified ·
1 Parent(s): 0d16a9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -277,14 +277,20 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
277
 
278
  full_response = generate_chunked_response(model, formatted_prompt)
279
 
280
- # Extract only the part after the specific sentence
281
- answer_pattern = r"Provide a concise and direct answer to the question without mentioning the web search or these instructions:([\s\S]*)"
282
- match = re.search(answer_pattern, full_response, re.IGNORECASE)
 
 
 
283
 
284
- if match:
285
- answer = match.group(1).strip()
 
 
 
286
  else:
287
- # If the specific sentence is not found, return the full response
288
  answer = full_response.strip()
289
 
290
  if not web_search:
 
277
 
278
  full_response = generate_chunked_response(model, formatted_prompt)
279
 
280
+ # Extract only the part after the last occurrence of a prompt-like sentence
281
+ answer_patterns = [
282
+ r"Provide a concise and direct answer to the question without mentioning the web search or these instructions:",
283
+ r"Provide a concise and direct answer to the question:",
284
+ r"Answer:"
285
+ ]
286
 
287
+ for pattern in answer_patterns:
288
+ match = re.split(pattern, full_response, flags=re.IGNORECASE)
289
+ if len(match) > 1:
290
+ answer = match[-1].strip()
291
+ break
292
  else:
293
+ # If no pattern is found, return the full response
294
  answer = full_response.strip()
295
 
296
  if not web_search: