Spaces:
Runtime error
Runtime error
Upload agent
Browse files- agent.json +5 -2
- app.py +5 -1
- requirements.txt +1 -0
- tools/suggest_menu.py +24 -0
- tools/web_search.py +27 -0
agent.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 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 |
}
|
|
@@ -38,6 +40,7 @@
|
|
| 38 |
"name": null,
|
| 39 |
"description": null,
|
| 40 |
"requirements": [
|
|
|
|
| 41 |
"smolagents"
|
| 42 |
],
|
| 43 |
"authorized_imports": [
|
|
|
|
| 1 |
{
|
| 2 |
"tools": [
|
| 3 |
+
"web_search",
|
| 4 |
+
"suggest_menu",
|
| 5 |
"final_answer"
|
| 6 |
],
|
| 7 |
"model": {
|
| 8 |
"class": "HfApiModel",
|
| 9 |
"data": {
|
| 10 |
+
"last_input_token_count": null,
|
| 11 |
+
"last_output_token_count": null,
|
| 12 |
"model_id": "Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 13 |
"provider": null
|
| 14 |
}
|
|
|
|
| 40 |
"name": null,
|
| 41 |
"description": null,
|
| 42 |
"requirements": [
|
| 43 |
+
"duckduckgo_search",
|
| 44 |
"smolagents"
|
| 45 |
],
|
| 46 |
"authorized_imports": [
|
app.py
CHANGED
|
@@ -5,6 +5,8 @@ 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 +16,8 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
| 14 |
provider=None,
|
| 15 |
)
|
| 16 |
|
|
|
|
|
|
|
| 17 |
final_answer = FinalAnswer()
|
| 18 |
|
| 19 |
|
|
@@ -22,7 +26,7 @@ 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=20,
|
| 28 |
verbosity_level=1,
|
|
|
|
| 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.suggest_menu import SimpleTool as SuggestMenu
|
| 10 |
from tools.final_answer import FinalAnswerTool as FinalAnswer
|
| 11 |
|
| 12 |
|
|
|
|
| 16 |
provider=None,
|
| 17 |
)
|
| 18 |
|
| 19 |
+
web_search = WebSearch()
|
| 20 |
+
suggest_menu = SuggestMenu()
|
| 21 |
final_answer = FinalAnswer()
|
| 22 |
|
| 23 |
|
|
|
|
| 26 |
|
| 27 |
agent = CodeAgent(
|
| 28 |
model=model,
|
| 29 |
+
tools=[web_search, suggest_menu],
|
| 30 |
managed_agents=[],
|
| 31 |
max_steps=20,
|
| 32 |
verbosity_level=1,
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
|
|
|
| 1 |
smolagents
|
|
|
|
| 1 |
+
duckduckgo_search
|
| 2 |
smolagents
|
tools/suggest_menu.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 17 |
+
if occasion == "casual":
|
| 18 |
+
return "Pizza, snacks and drinks"
|
| 19 |
+
elif occasion == "formal":
|
| 20 |
+
return "3-course dinner with wine and dessert"
|
| 21 |
+
elif occasion == "superhero":
|
| 22 |
+
return "Buffet with high-energy and healthy food"
|
| 23 |
+
else:
|
| 24 |
+
return "Custom menu for the butler"
|
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)
|