| import json | |
| import requests | |
| from pathlib import Path | |
| # API = "https://agents-course-unit4-scoring.hf.space" | |
| # questions = requests.get(f"{API}/questions").json() | |
| # print(len(questions)) | |
| # print(questions[0]) | |
| API = "https://agents-course-unit4-scoring.hf.space" | |
| CACHE = Path(__file__).parent / "questions.json" | |
| def load_questions(): | |
| if CACHE.exists(): | |
| return json.loads(CACHE.read_text()) | |
| questions = requests.get(f"{API}/questions").json() | |
| CACHE.write_text(json.dumps(questions, indent=2, ensure_ascii=False)) | |
| return questions | |
| if __name__ == "__main__": | |
| qs = load_questions() | |
| print(f" {len(qs)} questions fetched from {API}/questions") | |
| for q in qs: | |
| mark = "📎" if q["file_name"] else " " | |
| print(f'{mark} {q["task_id"][:8]} {q["question"][:70]}') | |
| from app import BasicAgent | |
| qs = load_questions() | |
| q = qs[2] | |
| print("Q:", q["question"]) | |
| agent = BasicAgent() | |
| print("A:", agent(q["question"])) |