File size: 1,002 Bytes
142bac6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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"]))