GilbertoEwaldFilho commited on
Commit
f1fba65
·
verified ·
1 Parent(s): 84b7eb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -28
app.py CHANGED
@@ -70,51 +70,55 @@ SYSTEM_PROMPT = (
70
  # =========================================================
71
  class BasicAgent:
72
  """
73
- Agente smolagents com DuckDuckGoSearchTool,
74
- otimizado para GAIA EXACT MATCH.
75
  """
76
 
77
  def __init__(self):
78
- print("Initializing GAIA agent with web search...")
79
 
80
- # ---- Token HF vindo do secret HF_TOKEN ----
81
- hf_token = os.getenv("HF_TOKEN")
82
- if not hf_token:
83
- print("⚠️ HF_TOKEN not found in environment! InferenceClient may fail.")
84
 
85
- # Cliente de inferência com token
86
- client = InferenceClient(token=hf_token) if hf_token else InferenceClient()
87
 
88
- # Modelo remoto via Inference API
89
- self.model = InferenceClientModel(client=client)
 
 
 
90
 
91
- # Ferramenta de busca
92
- self.search_tool = DuckDuckGoSearchTool()
 
 
 
 
 
 
 
 
 
 
 
93
 
94
- # CodeAgent com ferramenta de busca
95
  self.agent = CodeAgent(
96
  model=self.model,
97
  tools=[self.search_tool],
98
- max_steps=8, # permite alguns passos (buscar + refinar)
99
  )
100
 
101
  def __call__(self, question: str) -> str:
102
- print(f"\nProcessing question: {question[:80]}...")
103
  try:
104
- # Prompt completo passado para o agente
105
- full_prompt = (
106
- f"{SYSTEM_PROMPT}\n\n"
107
- f"Question: {question}\n\n"
108
- "Follow the rules above and return ONLY the exact final answer."
109
  )
110
-
111
- raw = self.agent.run(full_prompt)
112
- final = clean_answer(raw)
113
- print(f"Raw answer: {raw}")
114
- print(f"Final cleaned answer: {final}")
115
- return final
116
  except Exception as e:
117
- print(f"Error inside BasicAgent.__call__: {e}")
118
  return ""
119
 
120
 
 
70
  # =========================================================
71
  class BasicAgent:
72
  """
73
+ GAIA Agent powered by Mixtral + DuckDuckGo Search
 
74
  """
75
 
76
  def __init__(self):
77
+ print("Initializing improved GAIA agent...")
78
 
79
+ HF_TOKEN = os.getenv("HF_TOKEN")
80
+ if not HF_TOKEN:
81
+ print("❌ ERROR: HF_TOKEN secret not found!")
82
+ raise ValueError("HF_TOKEN missing")
83
 
84
+ # search tool
85
+ self.search_tool = DuckDuckGoSearchTool()
86
 
87
+ # LLM client (Mixtral)
88
+ client = InferenceClient(
89
+ model="mistralai/Mixtral-8x7B-Instruct-v0.1",
90
+ token=HF_TOKEN,
91
+ )
92
 
93
+ # Model wrapper
94
+ self.model = InferenceClientModel(
95
+ client=client,
96
+ system_prompt="""
97
+ You are a GAIA evaluation agent.
98
+
99
+ Rules:
100
+ - Use web search when needed.
101
+ - Output ONLY the final answer.
102
+ - No explanations, no reasoning, no URLs, no extra words.
103
+ - EXACT MATCH evaluation.
104
+ """,
105
+ )
106
 
107
+ # The real agent
108
  self.agent = CodeAgent(
109
  model=self.model,
110
  tools=[self.search_tool],
111
+ max_steps=5,
112
  )
113
 
114
  def __call__(self, question: str) -> str:
 
115
  try:
116
+ result = self.agent.run(
117
+ f"Answer this GAIA question. Return ONLY the final answer:\n{question}"
 
 
 
118
  )
119
+ return clean_answer(result)
 
 
 
 
 
120
  except Exception as e:
121
+ print(f"Agent error: {e}")
122
  return ""
123
 
124