Update app.py
Browse files
app.py
CHANGED
|
@@ -70,51 +70,55 @@ SYSTEM_PROMPT = (
|
|
| 70 |
# =========================================================
|
| 71 |
class BasicAgent:
|
| 72 |
"""
|
| 73 |
-
|
| 74 |
-
otimizado para GAIA EXACT MATCH.
|
| 75 |
"""
|
| 76 |
|
| 77 |
def __init__(self):
|
| 78 |
-
print("Initializing GAIA agent
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
#
|
| 92 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
-
#
|
| 95 |
self.agent = CodeAgent(
|
| 96 |
model=self.model,
|
| 97 |
tools=[self.search_tool],
|
| 98 |
-
max_steps=
|
| 99 |
)
|
| 100 |
|
| 101 |
def __call__(self, question: str) -> str:
|
| 102 |
-
print(f"\nProcessing question: {question[:80]}...")
|
| 103 |
try:
|
| 104 |
-
|
| 105 |
-
|
| 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"
|
| 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 |
|