Final_Assignment_Template / assignment_utils.py
jproman's picture
testing submission code
69e4888
raw
history blame
3.81 kB
import requests
import config
def getQuestions():
try:
response = requests.get(config.questionsUrl, timeout=15)
response.raise_for_status()
questions_data = response.json()
if not questions_data:
print("Fetched questions list is empty.")
raise Exception("Fetched questions list is empty")
print(f"Fetched {len(questions_data)} questions.")
return questions_data
except Exception as e:
print(f"An unexpected error occurred fetching questions: {e}")
return None
def getQuestionByPos(i):
questions = getQuestions()
return questions[i]
def printQuestions():
for i,question in enumerate(getQuestions()):
print(f"{i+1} ({question['task_id']}): {question['question']} {'(File: ' + question['file_name'] + ')' if question['file_name'] else ''}")
def submitAnswers(answers):
submission_data = {
"username": "jproman",
"agent_code": "https://huggingface.co/spaces/jproman/Final_Assignment_Template/tree/main",
"answers": answers
}
response = requests.post(config.submitUrl, json=submission_data, timeout=60)
response.raise_for_status()
result_data = response.json()
final_status = (
f"Submission Successful!\n"
f"User: {result_data.get('username')}\n"
f"Overall Score: {result_data.get('score', 'N/A')}% "
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
f"Message: {result_data.get('message', 'No message received.')}"
)
return final_status
def getTestAnswers():
task_id = ""
return [
{"task_id": "8e867cd7-cff9-4e6c-867a-ff5ddc2550be", "submitted_answer": "test answer"},
{"task_id": "a1e91b78-d3d8-4675-bb8d-62741b4b68a6", "submitted_answer": "test answer"},
{"task_id": "2d83110e-a098-4ebb-9987-066c06fa42d0", "submitted_answer": "test answer"},
{"task_id": "cca530fc-4052-43b2-b130-b30968d8aa44", "submitted_answer": "test answer"},
{"task_id": "4fc2f1ae-8625-45b5-ab34-ad4433bc21f8", "submitted_answer": "test answer"},
{"task_id": "6f37996b-2ac7-44b0-8e68-6d28256631b4", "submitted_answer": "test answer"},
{"task_id": "9d191bce-651d-4746-be2d-7ef8ecadb9c2", "submitted_answer": "test answer"},
{"task_id": "cabe07ed-9eca-40ea-8ead-410ef5e83f91", "submitted_answer": "test answer"},
{"task_id": "3cef3a44-215e-4aed-8e3b-b1e3f08063b7", "submitted_answer": "test answer"},
{"task_id": "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3", "submitted_answer": "test answer"},
{"task_id": "305ac316-eef6-4446-960a-92d80d542f82", "submitted_answer": "test answer"},
{"task_id": "f918266a-b3e0-4914-865d-4faa564f1aef", "submitted_answer": "test answer"},
{"task_id": "3f57289b-8c60-48be-bd80-01f8099ca449", "submitted_answer": "test answer"},
{"task_id": "1f975693-876d-457b-a649-393859e79bf3", "submitted_answer": "test answer"},
{"task_id": "840bfca7-4f7b-481a-8794-c560c340185d", "submitted_answer": "test answer"},
{"task_id": "bda648d7-d618-4883-88f4-3466eabd860e", "submitted_answer": "test answer"},
{"task_id": "cf106601-ab4f-4af9-b045-5295fe67b37d", "submitted_answer": "test answer"},
{"task_id": "a0c07678-e491-4bbc-8f0b-07405144218f", "submitted_answer": "test answer"},
{"task_id": "7bd855d8-463d-4ed5-93ca-5fe35145f733", "submitted_answer": "test answer"},
{"task_id": "5a0c1adf-205e-4841-a666-7c3ef95def9d", "submitted_answer": "test answer"},
]
if __name__ == "__main__":
# https://huggingface.co/spaces/agents-course/Students_leaderboard
questions = getQuestions()
printQuestions()
#response = submitAnswers(getTestAnswers())
#print(response)