Update app.py
Browse files
app.py
CHANGED
|
@@ -415,18 +415,24 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search, c
|
|
| 415 |
|
| 416 |
full_response = generate_chunked_response(model, formatted_prompt)
|
| 417 |
answer = extract_answer(full_response, instructions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
all_answers.append(answer)
|
| 419 |
break
|
| 420 |
|
| 421 |
except ValueError as ve:
|
| 422 |
print(f"Error in ask_question (attempt {attempt + 1}): {ve}")
|
| 423 |
if attempt == max_attempts - 1:
|
| 424 |
-
all_answers.append(f"I apologize, but I'm having trouble processing the query
|
| 425 |
|
| 426 |
except Exception as e:
|
| 427 |
print(f"Error in ask_question (attempt {attempt + 1}): {e}")
|
| 428 |
if attempt == max_attempts - 1:
|
| 429 |
-
all_answers.append(f"I apologize, but an unexpected error occurred. Please try again with a different question or check your internet connection.")
|
| 430 |
|
| 431 |
answer = "\n\n".join(all_answers)
|
| 432 |
sources = set(doc.metadata['source'] for doc in web_docs)
|
|
|
|
| 415 |
|
| 416 |
full_response = generate_chunked_response(model, formatted_prompt)
|
| 417 |
answer = extract_answer(full_response, instructions)
|
| 418 |
+
|
| 419 |
+
# Check if the answer is an error message
|
| 420 |
+
if answer.startswith("An error occurred while processing the response:"):
|
| 421 |
+
print(f"Error in extract_answer: {answer}")
|
| 422 |
+
raise ValueError(answer)
|
| 423 |
+
|
| 424 |
all_answers.append(answer)
|
| 425 |
break
|
| 426 |
|
| 427 |
except ValueError as ve:
|
| 428 |
print(f"Error in ask_question (attempt {attempt + 1}): {ve}")
|
| 429 |
if attempt == max_attempts - 1:
|
| 430 |
+
all_answers.append(f"I apologize, but I'm having trouble processing the query. Error: {ve}")
|
| 431 |
|
| 432 |
except Exception as e:
|
| 433 |
print(f"Error in ask_question (attempt {attempt + 1}): {e}")
|
| 434 |
if attempt == max_attempts - 1:
|
| 435 |
+
all_answers.append(f"I apologize, but an unexpected error occurred. Please try again with a different question or check your internet connection. Error: {e}")
|
| 436 |
|
| 437 |
answer = "\n\n".join(all_answers)
|
| 438 |
sources = set(doc.metadata['source'] for doc in web_docs)
|