corrigiendo en async
Browse files
app.py
CHANGED
|
@@ -29,9 +29,18 @@ class BasicAgent:
|
|
| 29 |
def __call__(self, question: str) -> str:
|
| 30 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 31 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
ctx = Context(self.workflow)
|
| 33 |
|
| 34 |
-
result =
|
|
|
|
|
|
|
| 35 |
|
| 36 |
answer = str(result)
|
| 37 |
|
|
@@ -40,6 +49,8 @@ class BasicAgent:
|
|
| 40 |
except Exception as e:
|
| 41 |
error_msg = f"I apologize, sir. I encountered an error: {str(e)}"
|
| 42 |
print(f"Error: {error_msg}")
|
|
|
|
|
|
|
| 43 |
return error_msg
|
| 44 |
#fixed_answer = "This is a default answer."
|
| 45 |
#print(f"Agent returning fixed answer: {fixed_answer}")
|
|
|
|
| 29 |
def __call__(self, question: str) -> str:
|
| 30 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 31 |
try:
|
| 32 |
+
try:
|
| 33 |
+
loop = asyncio.get_event_loop()
|
| 34 |
+
if loop.is_closed():
|
| 35 |
+
raise RuntimeError("Loop is closed")
|
| 36 |
+
except RuntimeError:
|
| 37 |
+
loop = asyncio.new_event_loop()
|
| 38 |
+
asyncio.set_event_loop(loop)
|
| 39 |
ctx = Context(self.workflow)
|
| 40 |
|
| 41 |
+
result = loop.run_until_complete(
|
| 42 |
+
self.workflow.run(ctx=ctx, question=question)
|
| 43 |
+
)
|
| 44 |
|
| 45 |
answer = str(result)
|
| 46 |
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
error_msg = f"I apologize, sir. I encountered an error: {str(e)}"
|
| 51 |
print(f"Error: {error_msg}")
|
| 52 |
+
import traceback
|
| 53 |
+
traceback.print_exc()
|
| 54 |
return error_msg
|
| 55 |
#fixed_answer = "This is a default answer."
|
| 56 |
#print(f"Agent returning fixed answer: {fixed_answer}")
|