Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,35 +10,35 @@ from Gradio_UI import GradioUI
|
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
# Replace this part in app.py
|
12 |
@tool
|
13 |
-
def my_custom_tool(
|
14 |
-
"""A tool that
|
15 |
Args:
|
16 |
-
|
17 |
-
|
18 |
"""
|
19 |
try:
|
20 |
-
# Initialize search tool
|
21 |
search_tool = DuckDuckGoSearchTool()
|
|
|
22 |
|
23 |
-
# Get results
|
24 |
-
results = search_tool(query)
|
25 |
-
|
26 |
-
# Format response
|
27 |
if not results:
|
28 |
-
return f"No information found
|
29 |
|
30 |
-
|
31 |
-
|
|
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
|
38 |
-
return
|
39 |
|
40 |
except Exception as e:
|
41 |
-
return f"Error
|
42 |
|
43 |
@tool
|
44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
# Replace this part in app.py
|
12 |
@tool
|
13 |
+
def my_custom_tool(search_topic: str, max_results: int) -> str:
|
14 |
+
"""A tool that performs a web search and returns formatted results
|
15 |
Args:
|
16 |
+
search_topic: The topic to search for
|
17 |
+
max_results: Number of results to return (1-3)
|
18 |
"""
|
19 |
try:
|
|
|
20 |
search_tool = DuckDuckGoSearchTool()
|
21 |
+
results = search_tool(search_topic)
|
22 |
|
|
|
|
|
|
|
|
|
23 |
if not results:
|
24 |
+
return f"No information found about '{search_topic}'"
|
25 |
|
26 |
+
# Limit number of results
|
27 |
+
max_results = min(max(1, max_results), 3)
|
28 |
+
results = results[:max_results]
|
29 |
|
30 |
+
# Format response like the time zone example
|
31 |
+
formatted_results = []
|
32 |
+
for result in results:
|
33 |
+
formatted_results.append(
|
34 |
+
f"Title: {result['title']}\n"
|
35 |
+
f"Summary: {result['snippet']}"
|
36 |
+
)
|
37 |
|
38 |
+
return "\n\n".join(formatted_results)
|
39 |
|
40 |
except Exception as e:
|
41 |
+
return f"Error searching for '{search_topic}': {str(e)}"
|
42 |
|
43 |
@tool
|
44 |
def get_current_time_in_timezone(timezone: str) -> str:
|