Update app.py
Browse filesInclude a duckduckgo_search tool
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -19,6 +19,21 @@ def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@tool
|
| 23 |
def linux_shell_interface(command: str) -> str:
|
| 24 |
"""A tool that executes a Debian Linux command and returns the output.
|
|
@@ -68,7 +83,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
-
tools=[final_answer, get_current_time_in_timezone, linux_shell_interface], ## add your tools here (don't remove final answer)
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
| 22 |
+
@tool
|
| 23 |
+
def duckduckgo_search(query: str, max_results: int = 5) -> list[dict]:
|
| 24 |
+
"""A tool that uses DuckDuckGo to search the internet and returns a list of results.
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
query: The search query string.
|
| 28 |
+
max_results: The maximum number of search results to return. Defaults to 5.
|
| 29 |
+
|
| 30 |
+
Returns:
|
| 31 |
+
list[dict]: A list of dictionaries, where each dictionary represents a search result and contains the keys 'title', 'href', and 'body'.
|
| 32 |
+
"""
|
| 33 |
+
ddgs = DuckDuckGoSearchTool()
|
| 34 |
+
results = ddgs.text(query, max_results=max_results)
|
| 35 |
+
return [r for r in results]
|
| 36 |
+
|
| 37 |
@tool
|
| 38 |
def linux_shell_interface(command: str) -> str:
|
| 39 |
"""A tool that executes a Debian Linux command and returns the output.
|
|
|
|
| 83 |
|
| 84 |
agent = CodeAgent(
|
| 85 |
model=model,
|
| 86 |
+
tools=[final_answer, get_current_time_in_timezone, linux_shell_interface, duckduckgo_search], ## add your tools here (don't remove final answer)
|
| 87 |
max_steps=6,
|
| 88 |
verbosity_level=1,
|
| 89 |
grammar=None,
|