Update app.py
Browse files
app.py
CHANGED
|
@@ -10,32 +10,39 @@ from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, Wi
|
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
class BasicAgent:
|
| 18 |
def __init__(self):
|
| 19 |
self.agent = CodeAgent(
|
| 20 |
tools=[DuckDuckGoSearchTool(), WikipediaSearchTool()],
|
| 21 |
-
model=InferenceClientModel(
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
-
self.agent = CodeAgent(
|
| 25 |
-
tools=[DuckDuckGoSearchTool(), WikipediaSearchTool()],
|
| 26 |
-
model=...,
|
| 27 |
-
max_steps=12,
|
| 28 |
-
additional_authorized_imports=["pandas", "numpy"],
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
SYSTEM_HINT = """Answer with ONLY the final answer — no explanation, no units unless asked,
|
| 32 |
-
no leading articles. If it's a number, write digits. If it's a list, comma-separated."""
|
| 33 |
|
| 34 |
-
def __call__(self, question: str) -> str:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
|
|
|
|
| 10 |
# --- Constants ---
|
| 11 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 12 |
|
| 13 |
+
import os
|
| 14 |
+
from smolagents import (
|
| 15 |
+
CodeAgent,
|
| 16 |
+
DuckDuckGoSearchTool,
|
| 17 |
+
InferenceClientModel,
|
| 18 |
+
WikipediaSearchTool,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
SYSTEM_HINT = (
|
| 22 |
+
"Answer with ONLY the final answer — no explanation, no units unless asked, "
|
| 23 |
+
"no leading articles. If it's a number, write digits. "
|
| 24 |
+
"If it's a list, comma-separated."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
|
| 28 |
class BasicAgent:
|
| 29 |
def __init__(self):
|
| 30 |
self.agent = CodeAgent(
|
| 31 |
tools=[DuckDuckGoSearchTool(), WikipediaSearchTool()],
|
| 32 |
+
model=InferenceClientModel(
|
| 33 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 34 |
+
token=os.getenv("HF_TOKEN"),
|
| 35 |
+
),
|
| 36 |
+
max_steps=12,
|
| 37 |
+
additional_authorized_imports=["pandas", "numpy"],
|
| 38 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
def __call__(self, question: str) -> str:
|
| 41 |
+
try:
|
| 42 |
+
return str(self.agent.run(f"{SYSTEM_HINT}\n\nQuestion: {question}"))
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"Agent failed on question: {e}")
|
| 45 |
+
return "unable to answer"
|
| 46 |
|
| 47 |
|
| 48 |
|