fixed random question test to work on single question
Browse files
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 |
-
|
| 50 |
-
if not
|
| 51 |
print("Fetched questions list is empty.")
|
| 52 |
return "Fetched questions list is empty or invalid format.", None
|
| 53 |
-
print(f"Fetched
|
| 54 |
except requests.exceptions.RequestException as e:
|
| 55 |
-
print(f"Error
|
| 56 |
-
return f"Error fetching
|
| 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
|
| 61 |
except Exception as e:
|
| 62 |
-
print(f"An unexpected error occurred fetching
|
| 63 |
-
return f"An unexpected error occurred fetching
|
| 64 |
|
| 65 |
results_log = []
|
| 66 |
answers_payload = []
|
| 67 |
-
print(f"Running agent on {len(
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 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.")
|