Nioi commited on
Commit
b61d222
·
1 Parent(s): 53eb347

fixed random question test to work on single question

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -46,38 +46,37 @@ def run_random_question(profile: gr.OAuthProfile | None):
46
  try:
47
  response = requests.get(random_question_url, timeout=15)
48
  response.raise_for_status()
49
- questions_data = response.json()
50
- if not questions_data:
51
  print("Fetched questions list is empty.")
52
  return "Fetched questions list is empty or invalid format.", None
53
- print(f"Fetched {len(questions_data)} questions.")
54
  except requests.exceptions.RequestException as e:
55
- print(f"Error fetching questions: {e}")
56
- return f"Error fetching questions: {e}", None
57
  except requests.exceptions.JSONDecodeError as e:
58
  print(f"Error decoding JSON response from questions endpoint: {e}")
59
  print(f"Response text: {response.text[:500]}")
60
- return f"Error decoding server response for questions: {e}", None
61
  except Exception as e:
62
- print(f"An unexpected error occurred fetching questions: {e}")
63
- return f"An unexpected error occurred fetching questions: {e}", None
64
 
65
  results_log = []
66
  answers_payload = []
67
- print(f"Running agent on {len(questions_data)} questions...")
68
- for item in questions_data:
69
- task_id = item.get("task_id")
70
- question_text = item.get("question")
71
- if not task_id or question_text is None:
72
- print(f"Skipping item with missing task_id or question: {item}")
73
- continue
74
- try:
75
- submitted_answer = agent(question_text)
76
- answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
77
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
78
- except Exception as e:
79
- print(f"Error running agent on task {task_id}: {e}")
80
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
81
 
82
  if not answers_payload:
83
  print("Agent did not produce any answers to submit.")
 
46
  try:
47
  response = requests.get(random_question_url, timeout=15)
48
  response.raise_for_status()
49
+ question_data = response.json()
50
+ if not question_data:
51
  print("Fetched questions list is empty.")
52
  return "Fetched questions list is empty or invalid format.", None
53
+ print(f"Fetched random question.")
54
  except requests.exceptions.RequestException as e:
55
+ print(f"Error fetchin random question: {e}")
56
+ return f"Error fetching random question: {e}", None
57
  except requests.exceptions.JSONDecodeError as e:
58
  print(f"Error decoding JSON response from questions endpoint: {e}")
59
  print(f"Response text: {response.text[:500]}")
60
+ return f"Error decoding server response for random question: {e}", None
61
  except Exception as e:
62
+ print(f"An unexpected error occurred fetching random question: {e}")
63
+ return f"An unexpected error occurred fetching random question: {e}", None
64
 
65
  results_log = []
66
  answers_payload = []
67
+ print(f"Running agent on {len(question_data)} questions...")
68
+ task_id = question_data.get("task_id")
69
+ question_text = question_data.get("question")
70
+ if not task_id or question_text is None:
71
+ print(f"Random question is missing task_id or question")
72
+ return "Random question is missing task_id or question", None
73
+ try:
74
+ submitted_answer = 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
  if not answers_payload:
82
  print("Agent did not produce any answers to submit.")