Spaces:
Sleeping
Sleeping
Add a web_search function
Browse files
app.py
CHANGED
|
@@ -9,14 +9,25 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def my_custom_tool(
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(query: str, max_results: int = 3)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""A web search tool that uses DuckDuckGo to fetch top search results via smolagents.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
+
query: The search query string from the user.
|
| 18 |
+
max_results: Maximum number of results to return (default: 3).
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
A string summarizing the top search results.
|
| 22 |
"""
|
| 23 |
+
tool = DuckDuckGoSearchTool()
|
| 24 |
+
full_result = tool(query)
|
| 25 |
+
|
| 26 |
+
# If the tool returns a long text, you can optionally trim it
|
| 27 |
+
result_lines = full_result.strip().split('\n')
|
| 28 |
+
limited_result = '\n'.join(result_lines[:max_results * 2]) # Approx: 2 lines per result
|
| 29 |
+
|
| 30 |
+
return limited_result or "No results found."
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|