Update app.py
Browse files
app.py
CHANGED
|
@@ -68,41 +68,60 @@ SYSTEM_PROMPT = (
|
|
| 68 |
|
| 69 |
class BasicAgent:
|
| 70 |
"""
|
| 71 |
-
Agente
|
| 72 |
-
|
| 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
|
| 79 |
|
| 80 |
-
# Ferramenta de busca (DuckDuckGo)
|
| 81 |
self.search_tool = DuckDuckGoSearchTool()
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
# Passamos o SYSTEM_PROMPT aqui
|
| 85 |
self.model = InferenceClientModel(
|
| 86 |
-
system_prompt=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
)
|
| 88 |
|
| 89 |
-
# CodeAgent com
|
| 90 |
self.agent = CodeAgent(
|
| 91 |
model=self.model,
|
| 92 |
tools=[self.search_tool],
|
| 93 |
-
max_steps=
|
| 94 |
)
|
| 95 |
|
| 96 |
def __call__(self, question: str) -> str:
|
| 97 |
-
print(f"
|
| 98 |
try:
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
| 103 |
except Exception as e:
|
| 104 |
-
print(f"Error
|
| 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 |
|