cowrycode commited on
Commit
bde156c
·
verified ·
1 Parent(s): b5c5078

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -19
app.py CHANGED
@@ -43,8 +43,8 @@ class BasicAgent:
43
  return answer
44
 
45
  def __call__(self, question: str) -> str:
46
- return asyncio.run(self.run(question))
47
- #return self.run(question)
48
  #print(f"Agent received question (first 50 chars): {question[:50]}...")
49
  #fixed_answer = "This is a default answer."
50
  #fixed_answer = self.llamaindex_agent.run(question)
@@ -105,23 +105,45 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
105
  results_log = []
106
  answers_payload = []
107
  print(f"Running agent on {len(questions_data)} questions...")
108
- for item in questions_data:
109
- task_id = item.get("task_id")
110
- question_text = item.get("question")
111
- if not task_id or question_text is None:
112
- print(f"Skipping item with missing task_id or question: {item}")
113
- continue
114
- try:
115
- submitted_answer = agent(question_text)
116
- answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
117
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
118
- except Exception as e:
119
- print(f"Error running agent on task {task_id}: {e}")
120
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
121
-
122
- if not answers_payload:
123
- print("Agent did not produce any answers to submit.")
124
- return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  # 4. Prepare Submission
127
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
 
43
  return answer
44
 
45
  def __call__(self, question: str) -> str:
46
+ #return asyncio.run(self.run(question))
47
+ return self.agent.run(question)
48
  #print(f"Agent received question (first 50 chars): {question[:50]}...")
49
  #fixed_answer = "This is a default answer."
50
  #fixed_answer = self.llamaindex_agent.run(question)
 
105
  results_log = []
106
  answers_payload = []
107
  print(f"Running agent on {len(questions_data)} questions...")
108
+ # for item in questions_data:
109
+ # task_id = item.get("task_id")
110
+ # question_text = item.get("question")
111
+ # if not task_id or question_text is None:
112
+ # print(f"Skipping item with missing task_id or question: {item}")
113
+ # continue
114
+ # try:
115
+ # submitted_answer = agent(question_text)
116
+ # answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
117
+ # results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
118
+ # except Exception as e:
119
+ # print(f"Error running agent on task {task_id}: {e}")
120
+ # results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
121
+
122
+ # if not answers_payload:
123
+ # print("Agent did not produce any answers to submit.")
124
+ # return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
125
+
126
+ #3A
127
+ async def run_all_questions(agent, questions_data):
128
+ answers_payload = []
129
+ for item in questions_data:
130
+ task_id = item.get("task_id")
131
+ question_text = item.get("question")
132
+ if not task_id or question_text is None:
133
+ print(f"Skipping item with missing task_id or question: {item}")
134
+ continue
135
+ try:
136
+ answer = await agent.run(question_text) # await coroutine
137
+ answers_payload.append({"task_id": task_id, "submitted_answer": answer})
138
+ print(f"Answered Task {task_id}: {answer[:50]}...")
139
+ except Exception as e:
140
+ answers_payload.append({"task_id": task_id, "submitted_answer": f"AGENT ERROR: {e}"})
141
+ print(f"Error on Task {task_id}: {e}")
142
+ return answers_payload
143
+
144
+ answers_payload = asyncio.run(run_all_questions(agent, questions_data))
145
+
146
+ #3B
147
 
148
  # 4. Prepare Submission
149
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}