Update app.py
Browse files
app.py
CHANGED
@@ -45,13 +45,50 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
45 |
question_text = item.get("question")
|
46 |
if not task_id or question_text is None:
|
47 |
continue
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
if not answers_payload:
|
57 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
|
|
45 |
question_text = item.get("question")
|
46 |
if not task_id or question_text is None:
|
47 |
continue
|
48 |
+
# 1. Add system prompt before the question
|
49 |
+
system_prompt = (
|
50 |
+
"You are a general AI assistant. I will ask you a question. "
|
51 |
+
"Report your thoughts, and finish your answer with the following template: "
|
52 |
+
"FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. "
|
53 |
+
"If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. "
|
54 |
+
"If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. "
|
55 |
+
"If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\n\n"
|
56 |
+
)
|
57 |
+
full_prompt = system_prompt + f"Question: {question_text.strip()}"
|
58 |
+
|
59 |
+
try:
|
60 |
+
agent_response = agent(full_prompt)
|
61 |
+
|
62 |
+
# 2. Extract final answer and reasoning
|
63 |
+
if "FINAL ANSWER:" in agent_response:
|
64 |
+
reasoning_trace, final_answer = agent_response.rsplit("FINAL ANSWER:", 1)
|
65 |
+
final_answer = final_answer.strip()
|
66 |
+
reasoning_trace = reasoning_trace.strip()
|
67 |
+
else:
|
68 |
+
final_answer = agent_response.strip()
|
69 |
+
reasoning_trace = "Model did not follow format; full response returned."
|
70 |
+
|
71 |
+
answer_entry = {
|
72 |
+
"task_id": task_id,
|
73 |
+
"model_answer": final_answer,
|
74 |
+
"reasoning_trace": reasoning_trace
|
75 |
+
}
|
76 |
+
answers_payload.append(answer_entry)
|
77 |
+
results_log.append({
|
78 |
+
"Task ID": task_id,
|
79 |
+
"Question": question_text,
|
80 |
+
"Submitted Answer": final_answer,
|
81 |
+
"Reasoning Trace": reasoning_trace
|
82 |
+
})
|
83 |
+
|
84 |
+
except Exception as e:
|
85 |
+
print(f"Error running agent on task {task_id}: {e}")
|
86 |
+
results_log.append({
|
87 |
+
"Task ID": task_id,
|
88 |
+
"Question": question_text,
|
89 |
+
"Submitted Answer": f"AGENT ERROR: {e}",
|
90 |
+
"Reasoning Trace": "N/A"
|
91 |
+
})
|
92 |
|
93 |
if not answers_payload:
|
94 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|