File size: 1,537 Bytes
91f2ed8 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import requests
import yaml
from smolagents import CodeAgent, HfApiModel
from tools.final_answer import FinalAnswerTool
GAIA_API = "https://gaia-api.spaces.huggingface.tech"
HF_USERNAME = "RoomSamurai"
SPACE_CODE_URL = f"https://huggingface.co/spaces/{HF_USERNAME}/AiAgentCourse_final_agent/tree/main"
with open("prompts.yaml", "r") as f:
prompt_templates = yaml.safe_load(f)
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct", temperature=0.5, max_tokens=2096)
final_answer = FinalAnswerTool()
agent = CodeAgent(
model=model,
tools=[final_answer],
prompt_templates=prompt_templates,
max_steps=6
)
def get_questions():
r = requests.get(f"{GAIA_API}/questions")
return r.json()
def submit_all(answers):
payload = {
"username": HF_USERNAME,
"agent_code": SPACE_CODE_URL,
"answers": answers
}
r = requests.post(f"{GAIA_API}/submit", json=payload)
return r.json()
if __name__ == "__main__":
print("Fetching GAIA questions...")
questions = get_questions()
submitted = []
for q in questions[:20]:
print("\nQuestion:", q["question"])
try:
response = agent.run(q["question"])
except Exception as e:
print("Agent error:", e)
response = "error"
submitted.append({
"task_id": q["id"],
"submitted_answer": str(response).strip()
})
print("\nSubmitting answers...")
result = submit_all(submitted)
print("Submission result:", result)
|