Martin Bär commited on
Commit
615b507
·
1 Parent(s): b43b66c

Properly await the agent result

Browse files
Files changed (2) hide show
  1. app.py +2 -2
  2. basic_agent.py +8 -5
app.py CHANGED
@@ -9,7 +9,7 @@ from basic_agent import BasicAgent
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
- def run_and_submit_all( profile: gr.OAuthProfile | None):
13
  """
14
  Fetches all questions, runs the BasicAgent on them, submits all answers,
15
  and displays the results.
@@ -70,7 +70,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
70
  print(f"Skipping item with missing task_id or question: {item}")
71
  continue
72
  try:
73
- submitted_answer = agent(question_text, task_id)
74
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
75
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
76
  except Exception as e:
 
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
+ async def run_and_submit_all( profile: gr.OAuthProfile | None):
13
  """
14
  Fetches all questions, runs the BasicAgent on them, submits all answers,
15
  and displays the results.
 
70
  print(f"Skipping item with missing task_id or question: {item}")
71
  continue
72
  try:
73
+ submitted_answer = await agent(question_text, task_id)
74
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
75
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
76
  except Exception as e:
basic_agent.py CHANGED
@@ -181,8 +181,11 @@ class BasicAgent:
181
 
182
  if self.langfuse:
183
  self.instrumentor.flush()
184
-
185
- res = await handler
186
- res = res.response.content
187
- res = re.sub(r'^.*?FINAL ANSWER:', '', res, flags=re.DOTALL).strip()
188
- return res
 
 
 
 
181
 
182
  if self.langfuse:
183
  self.instrumentor.flush()
184
+
185
+ try:
186
+ res = await handler
187
+ res = res.response.content
188
+ res = re.sub(r'^.*?FINAL ANSWER:', '', res, flags=re.DOTALL).strip()
189
+ return res
190
+ except:
191
+ return "No valid agent response could be determined."