Update app.py
Browse files
app.py
CHANGED
|
@@ -360,26 +360,41 @@ def fetch_questions(base_api_url: str) -> List[Dict[str, Any]]:
|
|
| 360 |
raise ValueError(f"Error decoding server response for questions: {e}") from e
|
| 361 |
|
| 362 |
def process_all_questions(agent: ChuckAgent, questions_data: List[Dict[str, Any]]) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
|
| 363 |
-
#
|
| 364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
model_ans, reasoning = agent(question_text)
|
| 366 |
-
except Exception as e:
|
|
|
|
| 367 |
logger.error(f"Error running agent on task {task_id}: {e}", exc_info=True)
|
| 368 |
model_ans = f"AGENT_CALL_ERROR: {e}"
|
| 369 |
reasoning = str(e)
|
| 370 |
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
answers_payload.append(payload_item)
|
| 376 |
|
| 377 |
-
results_log.append({
|
| 378 |
"Task ID": task_id,
|
| 379 |
"Question": question_text,
|
| 380 |
-
"Submitted Answer": model_ans,
|
| 381 |
"Reasoning Trace": reasoning
|
| 382 |
-
})
|
|
|
|
| 383 |
return answers_payload, results_log
|
| 384 |
|
| 385 |
def submit_answers(base_api_url: str, username: str, agent_code_url: str, answers_payload: List[Dict[str, Any]]) -> str:
|
|
|
|
| 360 |
raise ValueError(f"Error decoding server response for questions: {e}") from e
|
| 361 |
|
| 362 |
def process_all_questions(agent: ChuckAgent, questions_data: List[Dict[str, Any]]) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
|
| 363 |
+
# Level 1 indentation for lines inside the function
|
| 364 |
+
answers_payload = []
|
| 365 |
+
results_log = []
|
| 366 |
+
logger.info(f"Running agent on {len(questions_data)} questions...")
|
| 367 |
+
|
| 368 |
+
for i, item in enumerate(questions_data): # Level 1 indentation for the loop itself
|
| 369 |
+
# Level 2 indentation for lines inside the for loop
|
| 370 |
+
task_id = item.get("task_id")
|
| 371 |
+
question_text = item.get("question")
|
| 372 |
+
if not task_id or question_text is None:
|
| 373 |
+
logger.warning(f"Skipping item {i+1} with missing data: {item}")
|
| 374 |
+
continue # This continue is part of the if, which is part of the for
|
| 375 |
+
logger.info(f"Processing task {i+1}/{len(questions_data)}, ID: {task_id}")
|
| 376 |
+
model_ans, reasoning = "Error: Agent did not run", "No reasoning generated."
|
| 377 |
+
try: # Level 2 for try
|
| 378 |
+
# Level 3 for lines inside try
|
| 379 |
model_ans, reasoning = agent(question_text)
|
| 380 |
+
except Exception as e: # Level 2 for except
|
| 381 |
+
# Level 3 for lines inside except
|
| 382 |
logger.error(f"Error running agent on task {task_id}: {e}", exc_info=True)
|
| 383 |
model_ans = f"AGENT_CALL_ERROR: {e}"
|
| 384 |
reasoning = str(e)
|
| 385 |
|
| 386 |
+
payload_item = {"task_id": task_id, "submitted_answer": model_ans} # Level 2
|
| 387 |
+
if reasoning: # Level 2
|
| 388 |
+
payload_item["reasoning_trace"] = reasoning # Level 3
|
| 389 |
+
answers_payload.append(payload_item) # Level 2
|
|
|
|
| 390 |
|
| 391 |
+
results_log.append({ # Level 2
|
| 392 |
"Task ID": task_id,
|
| 393 |
"Question": question_text,
|
| 394 |
+
"Submitted Answer": model_ans,
|
| 395 |
"Reasoning Trace": reasoning
|
| 396 |
+
}) # Level 2 for the closing brace of append's argument
|
| 397 |
+
# The for loop has ended. Now, back to Level 1 indentation for the return.
|
| 398 |
return answers_payload, results_log
|
| 399 |
|
| 400 |
def submit_answers(base_api_url: str, username: str, agent_code_url: str, answers_payload: List[Dict[str, Any]]) -> str:
|