UPDATED app.py
#369
by Aishwaryas16 - opened
app.py
CHANGED
|
@@ -10,14 +10,38 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
print(
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
+
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, HfApiModel
|
| 14 |
+
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
+
print("Smart Agent initialized.")
|
| 18 |
+
|
| 19 |
+
self.model = HfApiModel(
|
| 20 |
+
model_id="mistralai/Mistral-7B-Instruct-v0.2"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
self.agent = ToolCallingAgent(
|
| 24 |
+
tools=[DuckDuckGoSearchTool()],
|
| 25 |
+
model=self.model,
|
| 26 |
+
max_steps=8,
|
| 27 |
+
name="gaia_agent",
|
| 28 |
+
description="Answers questions using web search"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
self.agent.system_prompt = """
|
| 32 |
+
Return ONLY the final answer.
|
| 33 |
+
No explanation.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
def __call__(self, question: str) -> str:
|
| 37 |
+
print("Running agent...")
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
result = self.agent.run(question)
|
| 41 |
+
clean = str(result).strip().split("\n")[0]
|
| 42 |
+
return clean
|
| 43 |
+
except:
|
| 44 |
+
return "unknown"
|
| 45 |
|
| 46 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 47 |
"""
|