Spaces:
Sleeping
Sleeping
added ddg search tool
Browse files
app.py
CHANGED
|
@@ -9,15 +9,24 @@ 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_cutom_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 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def my_cutom_tool(query:str)-> 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 tool that returns title of the first search result
|
| 15 |
Args:
|
| 16 |
+
query: A string representing the actual query to search on DuckDuckGo
|
|
|
|
| 17 |
"""
|
| 18 |
+
try:
|
| 19 |
+
searchtool = DuckDuckGoSearchTool()
|
| 20 |
+
results = searchtool.run(query)
|
| 21 |
+
if isinstance(results, list) and results:
|
| 22 |
+
return results[0]['title'] # Extract the title of the first result
|
| 23 |
+
elif isinstance(results, str):
|
| 24 |
+
return results # If it's already a formatted string
|
| 25 |
+
return "No results found."
|
| 26 |
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return f"Error fetching search results for {query} : {str(e)}"
|
| 29 |
+
|
| 30 |
@tool
|
| 31 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 32 |
"""A tool that fetches the current local time in a specified timezone.
|