Update app.py
Browse files
app.py
CHANGED
@@ -62,14 +62,28 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
62 |
agent_result = await loop.run_in_executor(None, agent, full_prompt)
|
63 |
|
64 |
# Try to extract final answer depending on type of result
|
|
|
65 |
if isinstance(agent_result, dict) and "final_answer" in agent_result:
|
66 |
final_answer = str(agent_result["final_answer"]).strip()
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
else:
|
71 |
final_answer = str(agent_result).strip()
|
72 |
|
|
|
73 |
answers_payload.append({
|
74 |
"task_id": task_id,
|
75 |
"model_answer": final_answer
|
|
|
62 |
agent_result = await loop.run_in_executor(None, agent, full_prompt)
|
63 |
|
64 |
# Try to extract final answer depending on type of result
|
65 |
+
# ✅ CLEAN AND PARSE AGENT OUTPUT
|
66 |
if isinstance(agent_result, dict) and "final_answer" in agent_result:
|
67 |
final_answer = str(agent_result["final_answer"]).strip()
|
68 |
+
|
69 |
+
elif isinstance(agent_result, str):
|
70 |
+
output = agent_result.strip()
|
71 |
+
|
72 |
+
# ✅ Remove any boilerplate text like: "Here is the final answer from your managed agent ..."
|
73 |
+
if "Here is the final answer from your managed agent" in output:
|
74 |
+
output = output.split(":", 1)[-1].strip()
|
75 |
+
|
76 |
+
# ✅ Extract only the text after "FINAL ANSWER:"
|
77 |
+
if "FINAL ANSWER:" in output:
|
78 |
+
_, final_answer = output.rsplit("FINAL ANSWER:", 1)
|
79 |
+
final_answer = final_answer.strip()
|
80 |
+
else:
|
81 |
+
final_answer = output # fallback
|
82 |
+
|
83 |
else:
|
84 |
final_answer = str(agent_result).strip()
|
85 |
|
86 |
+
|
87 |
answers_payload.append({
|
88 |
"task_id": task_id,
|
89 |
"model_answer": final_answer
|