Yago Bolivar
commited on
Commit
·
58b2d80
1
Parent(s):
b8a021d
feat: add basic API utilities
Browse files
utilities/compare_questions.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
with open("gaia_questions.json") as f:
|
4 |
+
initial_questions = json.load(f)
|
5 |
+
|
6 |
+
with open("new_gaia_questions.json") as f:
|
7 |
+
new_questions = json.load(f)
|
8 |
+
|
9 |
+
# Compare question IDs
|
10 |
+
initial_ids = {q["task_id"] for q in initial_questions}
|
11 |
+
new_ids = {q["task_id"] for q in new_questions}
|
12 |
+
|
13 |
+
added_questions = new_ids - initial_ids
|
14 |
+
removed_questions = initial_ids - new_ids
|
15 |
+
|
16 |
+
print(f"Added Questions: {added_questions}")
|
17 |
+
print(f"Removed Questions: {removed_questions}")
|
18 |
+
|
19 |
+
if not added_questions and not removed_questions:
|
20 |
+
print("✅ The question set has remained the same.")
|
21 |
+
else:
|
22 |
+
print("⚠️ The question set has changed.")
|
utilities/fetch_all_questions.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import os
|
3 |
+
import json
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
BASE_URL = os.getenv("BASE_URL")
|
9 |
+
|
10 |
+
def get_all_questions():
|
11 |
+
response = requests.get(f"{BASE_URL}/questions")
|
12 |
+
if response.status_code == 200:
|
13 |
+
return response.json()
|
14 |
+
else:
|
15 |
+
raise Exception(f"API request failed with status code {response.status_code}")
|
16 |
+
|
17 |
+
questions = get_all_questions()
|
18 |
+
|
19 |
+
print(f"Total questions retrieved: {len(questions)}")
|
20 |
+
|
21 |
+
with open("new_gaia_questions.json", "w") as file:
|
22 |
+
json.dump(questions, file, indent=4)
|
23 |
+
|
24 |
+
print("Questions successfully saved to new_gaia_questions.json")
|
utilities/random_question.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
BASE_URL = "https://agents-course-unit4-scoring.hf.space"
|
4 |
+
|
5 |
+
def get_random_question():
|
6 |
+
response = requests.get(f"{BASE_URL}/random-question")
|
7 |
+
return response.json()
|
8 |
+
|
9 |
+
def get_all_questions():
|
10 |
+
response = requests.get(f"{BASE_URL}/questions")
|
11 |
+
return response.json()
|
12 |
+
|
13 |
+
# Fetch one random question to test quickly
|
14 |
+
question = get_random_question()
|
15 |
+
print(question)
|
utilities/random_question_answer.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
+
|
7 |
+
USERNAME = os.getenv("USERNAME")
|
8 |
+
AGENT_CODE_URL = os.getenv("AGENT_CODE_URL")
|
9 |
+
BASE_URL = os.getenv("BASE_URL")
|
10 |
+
|
11 |
+
def get_random_question():
|
12 |
+
response = requests.get(f"{BASE_URL}/random-question")
|
13 |
+
return response.json()
|
14 |
+
|
15 |
+
def submit_answer(task_id, agent_answer):
|
16 |
+
payload = {
|
17 |
+
"username": USERNAME,
|
18 |
+
"agent_code": AGENT_CODE_URL,
|
19 |
+
"answers": [{"task_id": task_id, "submitted_answer": agent_answer}]
|
20 |
+
}
|
21 |
+
response = requests.post(f"{BASE_URL}/submit", json=payload)
|
22 |
+
return response.json()
|
23 |
+
|
24 |
+
# Example usage
|
25 |
+
question = get_random_question()
|
26 |
+
print(question)
|
27 |
+
|
28 |
+
# Replace the following line with your agent's actual answer generation
|
29 |
+
agent_answer = "your_agent_generated_answer"
|
30 |
+
|
31 |
+
submission_result = submit_answer(question["task_id"], agent_answer)
|
32 |
+
print(submission_result)
|