Update agent.py
Browse files
agent.py
CHANGED
|
@@ -2,13 +2,7 @@ import os
|
|
| 2 |
import logging
|
| 3 |
from typing import List, Dict, Any, Optional
|
| 4 |
|
| 5 |
-
from smolagents
|
| 6 |
-
from smolagents.llms import OpenAILLM
|
| 7 |
-
from smolagents.tools import Tool
|
| 8 |
-
from smolagents.tools.web_search import DuckDuckGoSearchTool
|
| 9 |
-
from smolagents.tools.wikipedia import WikipediaSearchTool
|
| 10 |
-
from smolagents.tools.arxiv import ArxivSearchTool
|
| 11 |
-
from smolagents.tools.code_interpreter import CodeInterpreterTool
|
| 12 |
|
| 13 |
# Configurazione del logging
|
| 14 |
logging.basicConfig(
|
|
@@ -33,19 +27,11 @@ class GaiaAgent:
|
|
| 33 |
raise ValueError("OPENAI_API_KEY non trovata. Configura il secret in Hugging Face.")
|
| 34 |
|
| 35 |
# Configurazione del modello LLM
|
| 36 |
-
self.
|
| 37 |
model="gpt-4.1",
|
| 38 |
api_key=api_key
|
| 39 |
)
|
| 40 |
|
| 41 |
-
# Configurazione degli strumenti
|
| 42 |
-
self.tools: List[Tool] = [
|
| 43 |
-
WikipediaSearchTool(),
|
| 44 |
-
DuckDuckGoSearchTool(),
|
| 45 |
-
ArxivSearchTool(),
|
| 46 |
-
CodeInterpreterTool()
|
| 47 |
-
]
|
| 48 |
-
|
| 49 |
# Istruzioni specifiche per il formato delle risposte
|
| 50 |
system_prompt = """You are a helpful assistant tasked with answering questions using a set of tools.
|
| 51 |
Your final answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
|
@@ -54,13 +40,13 @@ If you are asked for a string, don't use articles, neither abbreviations, and wr
|
|
| 54 |
Return ONLY the final answer line."""
|
| 55 |
|
| 56 |
# Creazione dell'agente
|
| 57 |
-
self.agent =
|
| 58 |
-
|
| 59 |
-
tools=self.tools,
|
| 60 |
system_prompt=system_prompt,
|
| 61 |
verbose=True # Per logging essenziale
|
| 62 |
)
|
| 63 |
|
|
|
|
| 64 |
logger.info("GaiaAgent inizializzato con successo")
|
| 65 |
|
| 66 |
def __call__(self, question: str) -> str:
|
|
|
|
| 2 |
import logging
|
| 3 |
from typing import List, Dict, Any, Optional
|
| 4 |
|
| 5 |
+
from smolagents import CodeAgent, tool, InferenceClientModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Configurazione del logging
|
| 8 |
logging.basicConfig(
|
|
|
|
| 27 |
raise ValueError("OPENAI_API_KEY non trovata. Configura il secret in Hugging Face.")
|
| 28 |
|
| 29 |
# Configurazione del modello LLM
|
| 30 |
+
self.model = InferenceClientModel(
|
| 31 |
model="gpt-4.1",
|
| 32 |
api_key=api_key
|
| 33 |
)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Istruzioni specifiche per il formato delle risposte
|
| 36 |
system_prompt = """You are a helpful assistant tasked with answering questions using a set of tools.
|
| 37 |
Your final answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
|
|
|
| 40 |
Return ONLY the final answer line."""
|
| 41 |
|
| 42 |
# Creazione dell'agente
|
| 43 |
+
self.agent = CodeAgent(
|
| 44 |
+
model=self.model,
|
|
|
|
| 45 |
system_prompt=system_prompt,
|
| 46 |
verbose=True # Per logging essenziale
|
| 47 |
)
|
| 48 |
|
| 49 |
+
# Configurazione degli strumenti avviene automaticamente in CodeAgent
|
| 50 |
logger.info("GaiaAgent inizializzato con successo")
|
| 51 |
|
| 52 |
def __call__(self, question: str) -> str:
|