Sonu313131 commited on
Commit
6706f7c
·
verified ·
1 Parent(s): e694fa1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -26
app.py CHANGED
@@ -45,21 +45,23 @@ 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
- # 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()
@@ -68,12 +70,12 @@ try:
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,
@@ -81,14 +83,14 @@ try:
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)
 
45
  question_text = item.get("question")
46
  if not task_id or question_text is None:
47
  continue
48
+ try:
49
+ # Construct full prompt with required system instructions
50
+ system_prompt = (
51
+ "You are a general AI assistant. I will ask you a question. "
52
+ "Report your thoughts, and finish your answer with the following template: "
53
+ "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. "
54
+ "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. "
55
+ "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. "
56
+ "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"
57
+ )
58
+ full_prompt = system_prompt + f"Question: {question_text.strip()}"
59
+
60
+ # Run agent with full prompt
61
+ loop = asyncio.get_event_loop()
62
+ agent_response = await loop.run_in_executor(None, agent, full_prompt)
63
+
64
+ # Extract FINAL ANSWER and reasoning
65
  if "FINAL ANSWER:" in agent_response:
66
  reasoning_trace, final_answer = agent_response.rsplit("FINAL ANSWER:", 1)
67
  final_answer = final_answer.strip()
 
70
  final_answer = agent_response.strip()
71
  reasoning_trace = "Model did not follow format; full response returned."
72
 
73
+ answers_payload.append({
74
  "task_id": task_id,
75
  "model_answer": final_answer,
76
  "reasoning_trace": reasoning_trace
77
+ })
78
+
79
  results_log.append({
80
  "Task ID": task_id,
81
  "Question": question_text,
 
83
  "Reasoning Trace": reasoning_trace
84
  })
85
 
86
+ except Exception as e:
87
+ print(f"Error running agent on task {task_id}: {e}")
88
+ results_log.append({
89
+ "Task ID": task_id,
90
+ "Question": question_text,
91
+ "Submitted Answer": f"AGENT ERROR: {e}",
92
+ "Reasoning Trace": "N/A"
93
+ })
94
 
95
  if not answers_payload:
96
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)