Upload agent
Browse files- agent.json +12 -4
- app.py +13 -3
- requirements.txt +3 -0
- tools/catering_service_tool.py +27 -0
- tools/suggest_menu.py +23 -0
- tools/superhero_party_theme_generator.py +22 -0
- tools/visit_webpage.py +45 -0
- tools/web_search.py +27 -0
agent.json
CHANGED
@@ -1,12 +1,17 @@
|
|
1 |
{
|
2 |
"tools": [
|
|
|
|
|
|
|
|
|
|
|
3 |
"final_answer"
|
4 |
],
|
5 |
"model": {
|
6 |
"class": "HfApiModel",
|
7 |
"data": {
|
8 |
-
"last_input_token_count":
|
9 |
-
"last_output_token_count":
|
10 |
"model_id": "Qwen/Qwen2.5-Coder-32B-Instruct",
|
11 |
"provider": null
|
12 |
}
|
@@ -31,13 +36,16 @@
|
|
31 |
"post_messages": "Based on the above, please provide an answer to the following user request:\n{{task}}"
|
32 |
}
|
33 |
},
|
34 |
-
"max_steps":
|
35 |
-
"verbosity_level":
|
36 |
"grammar": null,
|
37 |
"planning_interval": null,
|
38 |
"name": null,
|
39 |
"description": null,
|
40 |
"requirements": [
|
|
|
|
|
|
|
41 |
"smolagents"
|
42 |
],
|
43 |
"authorized_imports": [
|
|
|
1 |
{
|
2 |
"tools": [
|
3 |
+
"web_search",
|
4 |
+
"visit_webpage",
|
5 |
+
"suggest_menu",
|
6 |
+
"catering_service_tool",
|
7 |
+
"superhero_party_theme_generator",
|
8 |
"final_answer"
|
9 |
],
|
10 |
"model": {
|
11 |
"class": "HfApiModel",
|
12 |
"data": {
|
13 |
+
"last_input_token_count": 4058,
|
14 |
+
"last_output_token_count": 535,
|
15 |
"model_id": "Qwen/Qwen2.5-Coder-32B-Instruct",
|
16 |
"provider": null
|
17 |
}
|
|
|
36 |
"post_messages": "Based on the above, please provide an answer to the following user request:\n{{task}}"
|
37 |
}
|
38 |
},
|
39 |
+
"max_steps": 10,
|
40 |
+
"verbosity_level": 2,
|
41 |
"grammar": null,
|
42 |
"planning_interval": null,
|
43 |
"name": null,
|
44 |
"description": null,
|
45 |
"requirements": [
|
46 |
+
"duckduckgo_search",
|
47 |
+
"requests",
|
48 |
+
"markdownify",
|
49 |
"smolagents"
|
50 |
],
|
51 |
"authorized_imports": [
|
app.py
CHANGED
@@ -5,6 +5,11 @@ from smolagents import GradioUI, CodeAgent, HfApiModel
|
|
5 |
# Get current directory path
|
6 |
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
from tools.final_answer import FinalAnswerTool as FinalAnswer
|
9 |
|
10 |
|
@@ -14,6 +19,11 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
14 |
provider=None,
|
15 |
)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
final_answer = FinalAnswer()
|
18 |
|
19 |
|
@@ -22,10 +32,10 @@ with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
|
|
22 |
|
23 |
agent = CodeAgent(
|
24 |
model=model,
|
25 |
-
tools=[],
|
26 |
managed_agents=[],
|
27 |
-
max_steps=
|
28 |
-
verbosity_level=
|
29 |
grammar=None,
|
30 |
planning_interval=None,
|
31 |
name=None,
|
|
|
5 |
# Get current directory path
|
6 |
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
7 |
|
8 |
+
from tools.web_search import DuckDuckGoSearchTool as WebSearch
|
9 |
+
from tools.visit_webpage import VisitWebpageTool as VisitWebpage
|
10 |
+
from tools.suggest_menu import SimpleTool as SuggestMenu
|
11 |
+
from tools.catering_service_tool import SimpleTool as CateringServiceTool
|
12 |
+
from tools.superhero_party_theme_generator import SuperheroPartyThemeTool as SuperheroPartyThemeGenerator
|
13 |
from tools.final_answer import FinalAnswerTool as FinalAnswer
|
14 |
|
15 |
|
|
|
19 |
provider=None,
|
20 |
)
|
21 |
|
22 |
+
web_search = WebSearch()
|
23 |
+
visit_webpage = VisitWebpage()
|
24 |
+
suggest_menu = SuggestMenu()
|
25 |
+
catering_service_tool = CateringServiceTool()
|
26 |
+
superhero_party_theme_generator = SuperheroPartyThemeGenerator()
|
27 |
final_answer = FinalAnswer()
|
28 |
|
29 |
|
|
|
32 |
|
33 |
agent = CodeAgent(
|
34 |
model=model,
|
35 |
+
tools=[web_search, visit_webpage, suggest_menu, catering_service_tool, superhero_party_theme_generator],
|
36 |
managed_agents=[],
|
37 |
+
max_steps=10,
|
38 |
+
verbosity_level=2,
|
39 |
grammar=None,
|
40 |
planning_interval=None,
|
41 |
name=None,
|
requirements.txt
CHANGED
@@ -1 +1,4 @@
|
|
|
|
|
|
|
|
1 |
smolagents
|
|
|
1 |
+
duckduckgo_search
|
2 |
+
requests
|
3 |
+
markdownify
|
4 |
smolagents
|
tools/catering_service_tool.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import Tool
|
2 |
+
from typing import Any, Optional
|
3 |
+
|
4 |
+
class SimpleTool(Tool):
|
5 |
+
name = "catering_service_tool"
|
6 |
+
description = "This tool returns the highest-rated catering service in Gotham City."
|
7 |
+
inputs = {"query":{"type":"string","description":"A search term for finding catering services."}}
|
8 |
+
output_type = "string"
|
9 |
+
|
10 |
+
def forward(self, query: str) -> str:
|
11 |
+
"""
|
12 |
+
This tool returns the highest-rated catering service in Gotham City.
|
13 |
+
|
14 |
+
Args:
|
15 |
+
query: A search term for finding catering services.
|
16 |
+
"""
|
17 |
+
# Example list of catering services and their ratings
|
18 |
+
services = {
|
19 |
+
"Gotham Catering Co.": 4.9,
|
20 |
+
"Wayne Manor Catering": 4.8,
|
21 |
+
"Gotham City Events": 4.7,
|
22 |
+
}
|
23 |
+
|
24 |
+
# Find the highest rated catering service (simulating search query filtering)
|
25 |
+
best_service = max(services, key=services.get)
|
26 |
+
|
27 |
+
return best_service
|
tools/suggest_menu.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import Tool
|
2 |
+
from typing import Any, Optional
|
3 |
+
|
4 |
+
class SimpleTool(Tool):
|
5 |
+
name = "suggest_menu"
|
6 |
+
description = "Suggests a menu based on the occasion."
|
7 |
+
inputs = {"occasion":{"type":"string","description":"The type of occasion for the party."}}
|
8 |
+
output_type = "string"
|
9 |
+
|
10 |
+
def forward(self, occasion: str) -> str:
|
11 |
+
"""
|
12 |
+
Suggests a menu based on the occasion.
|
13 |
+
Args:
|
14 |
+
occasion: The type of occasion for the party.
|
15 |
+
"""
|
16 |
+
if occasion == "casual":
|
17 |
+
return "Pizza, snacks, and drinks."
|
18 |
+
elif occasion == "formal":
|
19 |
+
return "3-course dinner with wine and dessert."
|
20 |
+
elif occasion == "superhero":
|
21 |
+
return "Buffet with high-energy and healthy food."
|
22 |
+
else:
|
23 |
+
return "Custom menu for the butler."
|
tools/superhero_party_theme_generator.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
|
4 |
+
class SuperheroPartyThemeTool(Tool):
|
5 |
+
name = "superhero_party_theme_generator"
|
6 |
+
description = """
|
7 |
+
This tool suggests creative superhero-themed party ideas based on a category.
|
8 |
+
It returns a unique party theme idea."""
|
9 |
+
inputs = {'category': {'type': 'string', 'description': "The type of superhero party (e.g., 'classic heroes', 'villain masquerade', 'futuristic Gotham')."}}
|
10 |
+
output_type = "string"
|
11 |
+
|
12 |
+
def forward(self, category: str):
|
13 |
+
themes = {
|
14 |
+
"classic heroes": "Justice League Gala: Guests come dressed as their favorite DC heroes with themed cocktails like 'The Kryptonite Punch'.",
|
15 |
+
"villain masquerade": "Gotham Rogues' Ball: A mysterious masquerade where guests dress as classic Batman villains.",
|
16 |
+
"futuristic Gotham": "Neo-Gotham Night: A cyberpunk-style party inspired by Batman Beyond, with neon decorations and futuristic gadgets."
|
17 |
+
}
|
18 |
+
|
19 |
+
return themes.get(category.lower(), "Themed party idea not found. Try 'classic heroes', 'villain masquerade', or 'futuristic Gotham'.")
|
20 |
+
|
21 |
+
def __init__(self, *args, **kwargs):
|
22 |
+
self.is_initialized = False
|
tools/visit_webpage.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
import requests
|
4 |
+
import markdownify
|
5 |
+
import smolagents
|
6 |
+
|
7 |
+
class VisitWebpageTool(Tool):
|
8 |
+
name = "visit_webpage"
|
9 |
+
description = "Visits a webpage at the given url and reads its content as a markdown string. Use this to browse webpages."
|
10 |
+
inputs = {'url': {'type': 'string', 'description': 'The url of the webpage to visit.'}}
|
11 |
+
output_type = "string"
|
12 |
+
|
13 |
+
def forward(self, url: str) -> str:
|
14 |
+
try:
|
15 |
+
import requests
|
16 |
+
from markdownify import markdownify
|
17 |
+
from requests.exceptions import RequestException
|
18 |
+
|
19 |
+
from smolagents.utils import truncate_content
|
20 |
+
except ImportError as e:
|
21 |
+
raise ImportError(
|
22 |
+
"You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`."
|
23 |
+
) from e
|
24 |
+
try:
|
25 |
+
# Send a GET request to the URL with a 20-second timeout
|
26 |
+
response = requests.get(url, timeout=20)
|
27 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
28 |
+
|
29 |
+
# Convert the HTML content to Markdown
|
30 |
+
markdown_content = markdownify(response.text).strip()
|
31 |
+
|
32 |
+
# Remove multiple line breaks
|
33 |
+
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
|
34 |
+
|
35 |
+
return truncate_content(markdown_content, 10000)
|
36 |
+
|
37 |
+
except requests.exceptions.Timeout:
|
38 |
+
return "The request timed out. Please try again later or check the URL."
|
39 |
+
except RequestException as e:
|
40 |
+
return f"Error fetching the webpage: {str(e)}"
|
41 |
+
except Exception as e:
|
42 |
+
return f"An unexpected error occurred: {str(e)}"
|
43 |
+
|
44 |
+
def __init__(self, *args, **kwargs):
|
45 |
+
self.is_initialized = False
|
tools/web_search.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
import duckduckgo_search
|
4 |
+
|
5 |
+
class DuckDuckGoSearchTool(Tool):
|
6 |
+
name = "web_search"
|
7 |
+
description = "Performs a duckduckgo web search based on your query (think a Google search) then returns the top search results."
|
8 |
+
inputs = {'query': {'type': 'string', 'description': 'The search query to perform.'}}
|
9 |
+
output_type = "string"
|
10 |
+
|
11 |
+
def __init__(self, max_results=10, **kwargs):
|
12 |
+
super().__init__()
|
13 |
+
self.max_results = max_results
|
14 |
+
try:
|
15 |
+
from duckduckgo_search import DDGS
|
16 |
+
except ImportError as e:
|
17 |
+
raise ImportError(
|
18 |
+
"You must install package `duckduckgo_search` to run this tool: for instance run `pip install duckduckgo-search`."
|
19 |
+
) from e
|
20 |
+
self.ddgs = DDGS(**kwargs)
|
21 |
+
|
22 |
+
def forward(self, query: str) -> str:
|
23 |
+
results = self.ddgs.text(query, max_results=self.max_results)
|
24 |
+
if len(results) == 0:
|
25 |
+
raise Exception("No results found! Try a less restrictive/shorter query.")
|
26 |
+
postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
|
27 |
+
return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
|