RoomSamurai commited on
Commit
91f2ed8
·
verified ·
1 Parent(s): 68ede5a

Create gaia_submit.py

Browse files
Files changed (1) hide show
  1. gaia_submit.py +57 -0
gaia_submit.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import yaml
3
+ from smolagents import CodeAgent, HfApiModel
4
+ from tools.final_answer import FinalAnswerTool
5
+
6
+ GAIA_API = "https://gaia-api.spaces.huggingface.tech"
7
+ HF_USERNAME = "RoomSamurai"
8
+ SPACE_CODE_URL = f"https://huggingface.co/spaces/{HF_USERNAME}/AiAgentCourse_final_agent/tree/main"
9
+
10
+ with open("prompts.yaml", "r") as f:
11
+ prompt_templates = yaml.safe_load(f)
12
+
13
+ model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct", temperature=0.5, max_tokens=2096)
14
+ final_answer = FinalAnswerTool()
15
+
16
+ agent = CodeAgent(
17
+ model=model,
18
+ tools=[final_answer],
19
+ prompt_templates=prompt_templates,
20
+ max_steps=6
21
+ )
22
+
23
+ def get_questions():
24
+ r = requests.get(f"{GAIA_API}/questions")
25
+ return r.json()
26
+
27
+ def submit_all(answers):
28
+ payload = {
29
+ "username": HF_USERNAME,
30
+ "agent_code": SPACE_CODE_URL,
31
+ "answers": answers
32
+ }
33
+ r = requests.post(f"{GAIA_API}/submit", json=payload)
34
+ return r.json()
35
+
36
+ if __name__ == "__main__":
37
+ print("Fetching GAIA questions...")
38
+ questions = get_questions()
39
+
40
+ submitted = []
41
+
42
+ for q in questions[:20]:
43
+ print("\nQuestion:", q["question"])
44
+ try:
45
+ response = agent.run(q["question"])
46
+ except Exception as e:
47
+ print("Agent error:", e)
48
+ response = "error"
49
+
50
+ submitted.append({
51
+ "task_id": q["id"],
52
+ "submitted_answer": str(response).strip()
53
+ })
54
+
55
+ print("\nSubmitting answers...")
56
+ result = submit_all(submitted)
57
+ print("Submission result:", result)