Update app.py
Browse files
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
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
| 286 |
else:
|
| 287 |
-
# If
|
| 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:
|