Final_Assignment_Template / local_test.py
zaizou's picture
Upload 5 files
d03c5e0 verified
Raw History Blame Contribute Delete
1.82 kB
# local_test.py
from core_agent import GAIAAgent
import json
import requests
from pathlib import Path
API_URL = "https://agents-course-unit4-scoring.hf.space/questions"
agent = GAIAAgent()
def fetch_real_questions():
try:
print("📡 Fetching GAIA-style questions from HF server...")
response = requests.get(API_URL, timeout=15)
response.raise_for_status()
questions = response.json()
return questions
except Exception as e:
print(f"❌ Failed to fetch questions: {e}")
return []
def main():
questions = fetch_real_questions()
if not questions:
print("⚠️ No questions found. Exiting.")
return
results = []
for i, q in enumerate(questions, 1):
task_id = q.get("task_id")
question_text = q.get("question")
print(f"\n[{i}] Task ID: {task_id}")
print(f"📨 Question: {question_text}")
try:
answer = agent.answer_question(question_text)
print(f"✅ Answer: {answer}")
results.append({
"task_id": task_id,
"question": question_text,
"submitted_answer": answer
})
except Exception as e:
print(f"❌ Error: {e}")
results.append({
"task_id": task_id,
"question": question_text,
"submitted_answer": f"ERROR: {e}"
})
# Optional: save answers locally
save_path = Path("gaia_local_results.json")
with save_path.open("w", encoding="utf-8") as f:
json.dump(results, f, ensure_ascii=False, indent=4)
print(f"\n📝 Saved results to: {save_path.absolute()}")
if __name__ == "__main__":
main()