Update app.py
Browse files
app.py
CHANGED
|
@@ -255,7 +255,7 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
| 255 |
{context}
|
| 256 |
Current Question: {question}
|
| 257 |
If the web search results don't contain relevant information, state that the information is not available in the search results.
|
| 258 |
-
Provide a concise and direct answer to the question:
|
| 259 |
"""
|
| 260 |
prompt_val = ChatPromptTemplate.from_template(prompt_template)
|
| 261 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
|
@@ -277,18 +277,15 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
| 277 |
|
| 278 |
full_response = generate_chunked_response(model, formatted_prompt)
|
| 279 |
|
| 280 |
-
#
|
| 281 |
-
answer_pattern = r"
|
| 282 |
match = re.search(answer_pattern, full_response, re.IGNORECASE)
|
| 283 |
|
| 284 |
if match:
|
| 285 |
answer = match.group(1).strip()
|
| 286 |
else:
|
| 287 |
-
# If
|
| 288 |
-
answer =
|
| 289 |
-
|
| 290 |
-
# Remove any numbered list formatting
|
| 291 |
-
answer = re.sub(r'^\s*\d+\.\s*', '', answer, flags=re.MULTILINE)
|
| 292 |
|
| 293 |
if not web_search:
|
| 294 |
memory_database[question] = answer
|
|
|
|
| 255 |
{context}
|
| 256 |
Current Question: {question}
|
| 257 |
If the web search results don't contain relevant information, state that the information is not available in the search results.
|
| 258 |
+
Provide a concise and direct answer to the question without mentioning the web search or these instructions:
|
| 259 |
"""
|
| 260 |
prompt_val = ChatPromptTemplate.from_template(prompt_template)
|
| 261 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
|
|
|
| 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:
|
| 291 |
memory_database[question] = answer
|