Commit ·
25b8be7
1
Parent(s): a679f34
Move question answering to a separate function for easier debugging.
Browse files
app.py
CHANGED
|
@@ -64,6 +64,21 @@ def fetch_questions(api_url: str = DEFAULT_API_URL):
|
|
| 64 |
return questions_data
|
| 65 |
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 68 |
"""
|
| 69 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
@@ -115,18 +130,7 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 115 |
answers_payload = []
|
| 116 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 117 |
for item in questions_data:
|
| 118 |
-
|
| 119 |
-
question_text = item.get("question")
|
| 120 |
-
if not task_id or question_text is None:
|
| 121 |
-
print(f"Skipping item with missing task_id or question: {item}")
|
| 122 |
-
continue
|
| 123 |
-
try:
|
| 124 |
-
submitted_answer = await agent(question_text)
|
| 125 |
-
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 126 |
-
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 127 |
-
except Exception as e:
|
| 128 |
-
print(f"Error running agent on task {task_id}: {e}")
|
| 129 |
-
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 130 |
|
| 131 |
if not answers_payload:
|
| 132 |
print("Agent did not produce any answers to submit.")
|
|
|
|
| 64 |
return questions_data
|
| 65 |
|
| 66 |
|
| 67 |
+
async def answer_question(agent, item, answers_payload, results_log):
|
| 68 |
+
task_id = item.get("task_id")
|
| 69 |
+
question_text = item.get("question")
|
| 70 |
+
if not task_id or question_text is None:
|
| 71 |
+
print(f"Skipping item with missing task_id or question: {item}")
|
| 72 |
+
return
|
| 73 |
+
try:
|
| 74 |
+
submitted_answer = await agent(question_text)
|
| 75 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 76 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 77 |
+
except Exception as e:
|
| 78 |
+
print(f"Error running agent on task {task_id}: {e}")
|
| 79 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 80 |
+
|
| 81 |
+
|
| 82 |
async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 83 |
"""
|
| 84 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 130 |
answers_payload = []
|
| 131 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 132 |
for item in questions_data:
|
| 133 |
+
await answer_question(agent, item, answers_payload, results_log)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
if not answers_payload:
|
| 136 |
print("Agent did not produce any answers to submit.")
|