Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,8 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
# 🔹 NOVO: imports do smolagents
|
| 8 |
-
from smolagents import CodeAgent, InferenceClientModel
|
|
|
|
| 9 |
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -52,9 +53,13 @@ def clean_answer(text: str) -> str:
|
|
| 52 |
# =========================================================
|
| 53 |
|
| 54 |
SYSTEM_PROMPT = (
|
| 55 |
-
"You are an
|
| 56 |
-
"
|
| 57 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
"If the answer is a number, output just the number. "
|
| 59 |
"If it is a word or short phrase, output just that.\n"
|
| 60 |
"Your output will be compared to the ground truth using EXACT MATCH."
|
|
@@ -63,25 +68,29 @@ SYSTEM_PROMPT = (
|
|
| 63 |
|
| 64 |
class BasicAgent:
|
| 65 |
"""
|
| 66 |
-
Agente simples baseado em smolagents:
|
| 67 |
- Usa InferenceClientModel (Inference API da Hugging Face)
|
| 68 |
-
-
|
| 69 |
- Retorna uma string já limpa para EXACT MATCH
|
| 70 |
"""
|
| 71 |
|
| 72 |
def __init__(self):
|
| 73 |
-
print("Initializing smolagents BasicAgent...")
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
#
|
|
|
|
| 76 |
self.model = InferenceClientModel(
|
| 77 |
system_prompt=SYSTEM_PROMPT
|
| 78 |
)
|
| 79 |
|
| 80 |
-
# CodeAgent
|
| 81 |
self.agent = CodeAgent(
|
| 82 |
model=self.model,
|
| 83 |
-
tools=[],
|
| 84 |
-
max_steps=
|
| 85 |
)
|
| 86 |
|
| 87 |
def __call__(self, question: str) -> str:
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
# 🔹 NOVO: imports do smolagents
|
| 8 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
|
| 9 |
+
|
| 10 |
|
| 11 |
# --- Constants ---
|
| 12 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 53 |
# =========================================================
|
| 54 |
|
| 55 |
SYSTEM_PROMPT = (
|
| 56 |
+
"You are an AI agent solving GAIA-style questions.\n"
|
| 57 |
+
"You have access to a web search tool (DuckDuckGoSearchTool).\n"
|
| 58 |
+
"For each question, you MUST search the web when needed to obtain accurate, "
|
| 59 |
+
"up-to-date factual information before answering.\n"
|
| 60 |
+
"Use the search tool, read the results, reason, and then produce ONLY the final answer.\n"
|
| 61 |
+
"Do NOT output explanations, steps, reasoning, citations, links, or any extra words.\n"
|
| 62 |
+
"Do NOT output labels like 'Final answer', 'Answer:', etc.\n"
|
| 63 |
"If the answer is a number, output just the number. "
|
| 64 |
"If it is a word or short phrase, output just that.\n"
|
| 65 |
"Your output will be compared to the ground truth using EXACT MATCH."
|
|
|
|
| 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:
|