GilbertoEwaldFilho commited on
Commit
18d75cb
·
verified ·
1 Parent(s): e6e09db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -18
app.py CHANGED
@@ -68,41 +68,60 @@ SYSTEM_PROMPT = (
68
 
69
  class BasicAgent:
70
  """
71
- Agente simples baseado em smolagents, mas agora com ferramenta de busca:
72
- - Usa InferenceClientModel (Inference API da Hugging Face)
73
- - Usa DuckDuckGoSearchTool para buscar informações na web
74
- - Retorna uma string já limpa para EXACT MATCH
75
  """
76
 
77
  def __init__(self):
78
- print("Initializing smolagents BasicAgent with web search...")
79
 
80
- # Ferramenta de busca (DuckDuckGo)
81
  self.search_tool = DuckDuckGoSearchTool()
82
 
83
- # Modelo remoto via Inference API (usa HF_TOKEN configurado no Space)
84
- # Passamos o SYSTEM_PROMPT aqui
85
  self.model = InferenceClientModel(
86
- system_prompt=SYSTEM_PROMPT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  )
88
 
89
- # CodeAgent com ferramenta de busca
90
  self.agent = CodeAgent(
91
  model=self.model,
92
  tools=[self.search_tool],
93
- max_steps=5, # permite alguns passos (pensar + buscar + responder)
94
  )
95
 
96
  def __call__(self, question: str) -> str:
97
- print(f"Agent received question (first 80 chars): {question[:80]}...")
98
  try:
99
- raw_answer = self.agent.run(question)
100
- fixed_answer = clean_answer(raw_answer)
101
- print(f"Agent returning cleaned answer: {fixed_answer}")
102
- return fixed_answer
 
 
 
103
  except Exception as e:
104
- print(f"Error inside BasicAgent.__call__: {e}")
105
- # Em caso de erro, devolve string vazia (melhor do que quebrar tudo)
106
  return ""
107
 
108
 
 
68
 
69
  class BasicAgent:
70
  """
71
+ Agente smolagents com DuckDuckGoSearchTool,
72
+ otimizado para GAIA EXACT MATCH.
 
 
73
  """
74
 
75
  def __init__(self):
76
+ print("Initializing improved GAIA agent with search...")
77
 
 
78
  self.search_tool = DuckDuckGoSearchTool()
79
 
80
+ # Prompt especializado
 
81
  self.model = InferenceClientModel(
82
+ system_prompt=(
83
+ "You are a GAIA evaluation agent that must answer EXACTLY the final answer.\n"
84
+ "You MUST use the search tool to retrieve verified information.\n"
85
+ "When you use search, read the results and extract ONLY the exact required answer.\n"
86
+ "RULES:\n"
87
+ " - Output MUST be a SINGLE short string.\n"
88
+ " - NO explanations.\n"
89
+ " - NO reasoning.\n"
90
+ " - NO multi-sentence output.\n"
91
+ " - NO citations or URLs.\n"
92
+ " - NO extra words.\n"
93
+ "Examples of valid outputs:\n"
94
+ " '2002'\n"
95
+ " '7'\n"
96
+ " 'egalitarian'\n"
97
+ " 'Mercedes Sosa'\n"
98
+ "INVALID OUTPUTS:\n"
99
+ " 'The final answer is 7.'\n"
100
+ " 'According to Wikipedia, the answer is 2002.'\n"
101
+ " 'After checking, I think it is 3.'\n"
102
+ "Your response MUST be only the exact final answer.\n"
103
+ )
104
  )
105
 
106
+ # CodeAgent com raciocínio guiado
107
  self.agent = CodeAgent(
108
  model=self.model,
109
  tools=[self.search_tool],
110
+ max_steps=8, # permite buscar e refinar
111
  )
112
 
113
  def __call__(self, question: str) -> str:
114
+ print(f"Processing: {question[:80]}...")
115
  try:
116
+ raw = self.agent.run(
117
+ f"Answer this question using search:\n{question}\n"
118
+ "Return ONLY the exact final answer."
119
+ )
120
+ final = clean_answer(raw)
121
+ print(f"Final cleaned answer: {final}")
122
+ return final
123
  except Exception as e:
124
+ print(f"Error: {e}")
 
125
  return ""
126
 
127