Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -529,7 +529,7 @@ def answer_question(user_question, chatbot, audio=None):
|
|
| 529 |
|
| 530 |
while iterations < max_iterations:
|
| 531 |
|
| 532 |
-
|
| 533 |
email_match = re.search(r"send email to ([\w\.-]+@[\w\.-]+)", user_question)
|
| 534 |
if email_match:
|
| 535 |
user_email = email_match.group(1).strip()
|
|
@@ -537,18 +537,18 @@ def answer_question(user_question, chatbot, audio=None):
|
|
| 537 |
user_question = f"{user_question}:{user_email}"
|
| 538 |
"""
|
| 539 |
|
| 540 |
-
|
| 541 |
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
|
| 550 |
-
|
| 551 |
-
|
| 552 |
|
| 553 |
if os.getenv("IMAGE_PATH") in response_text:
|
| 554 |
# Open the image file
|
|
|
|
| 529 |
|
| 530 |
while iterations < max_iterations:
|
| 531 |
|
| 532 |
+
"""if "send email to" in user_question:
|
| 533 |
email_match = re.search(r"send email to ([\w\.-]+@[\w\.-]+)", user_question)
|
| 534 |
if email_match:
|
| 535 |
user_email = email_match.group(1).strip()
|
|
|
|
| 537 |
user_question = f"{user_question}:{user_email}"
|
| 538 |
"""
|
| 539 |
|
| 540 |
+
response = agent_executor.invoke({"input": user_question}, config={"callbacks": [langfuse_handler]})
|
| 541 |
|
| 542 |
+
if isinstance(response, dict):
|
| 543 |
+
response_text = response.get("output", "")
|
| 544 |
+
else:
|
| 545 |
+
response_text = response
|
| 546 |
+
if "invalid" not in response_text.lower():
|
| 547 |
+
break
|
| 548 |
+
iterations += 1
|
| 549 |
|
| 550 |
+
if iterations == max_iterations:
|
| 551 |
+
return "The agent could not generate a valid response within the iteration limit."
|
| 552 |
|
| 553 |
if os.getenv("IMAGE_PATH") in response_text:
|
| 554 |
# Open the image file
|