| """ |
| GAIA Level-1 agent powered by smolagents β₯ 0.6 |
| """ |
| from __future__ import annotations |
| import os, textwrap |
| from smolagents import CodeAgent, DuckDuckGoSearchTool |
| from tools import WikipediaTool, ArxivTool |
| import openai |
|
|
| |
| openai.api_key = os.getenv("OPENAI_API_KEY") or "" |
| if not openai.api_key: |
| raise EnvironmentError("OPENAI_API_KEY non trovata β aggiungila nei Secrets dello Space.") |
|
|
| |
| SYSTEM_PROMPT = textwrap.dedent(""" |
| You are a helpful assistant tasked with answering questions using a set of tools. |
| Your final answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. |
| If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. |
| If you are asked for a string, don't use articles, neither abbreviations, and write digits in plain text unless specified otherwise. |
| Return ONLY the final answer line. |
| """).strip() |
|
|
| |
| MODEL_ID = os.getenv("GAIA_MODEL_ID", "gpt-4o") |
|
|
| core_agent = CodeAgent( |
| model=MODEL_ID, |
| tools=[ |
| DuckDuckGoSearchTool(), |
| WikipediaTool(), |
| ArxivTool(), |
| ], |
| max_steps=6, |
| temperature=0, |
| system_prompt=SYSTEM_PROMPT, |
| stream_outputs=False, |
| ) |
|
|
| |
| class BasicAgent: |
| def __init__(self): |
| print("β
smolagents BasicAgent avviato") |
|
|
| def __call__(self, question: str) -> str: |
| raw = core_agent.run(question) |
| return raw.strip().split("\n", 1)[0] |
|
|