Update app.py
Browse files
app.py
CHANGED
@@ -10,23 +10,28 @@ 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 |
-
from
|
|
|
|
|
14 |
import os
|
15 |
|
16 |
class BasicAgent:
|
17 |
def __init__(self):
|
18 |
-
print("
|
19 |
-
self.
|
20 |
-
"
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
|
25 |
def __call__(self, question: str) -> str:
|
26 |
-
|
27 |
-
result = self.generator(prompt, max_new_tokens=50, truncation=True)
|
28 |
-
return result[0]['generated_text'].strip()
|
29 |
-
|
30 |
|
31 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
32 |
"""
|
|
|
10 |
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
+
from smolagent.agent import ToolCallingAgent
|
14 |
+
from smolagent.models.hf_api import HfApiModel
|
15 |
+
from smolagent.tools.duckduckgo import DuckDuckGoSearchTool
|
16 |
import os
|
17 |
|
18 |
class BasicAgent:
|
19 |
def __init__(self):
|
20 |
+
print("✅ Agent with search + model ready...")
|
21 |
+
self.model = HfApiModel(
|
22 |
+
model="mistralai/Mistral-7B-Instruct-v0.2", # or flan-t5-xl if smaller
|
23 |
+
api_key=os.getenv("HF_API_KEY")
|
24 |
+
)
|
25 |
+
self.agent = ToolCallingAgent(
|
26 |
+
name="search_agent",
|
27 |
+
description="Agent that can use web search and answer questions.",
|
28 |
+
model=self.model,
|
29 |
+
tools=[DuckDuckGoSearchTool()],
|
30 |
+
max_steps=4
|
31 |
)
|
32 |
|
33 |
def __call__(self, question: str) -> str:
|
34 |
+
return self.agent.run(question).strip()
|
|
|
|
|
|
|
35 |
|
36 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
37 |
"""
|