Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,38 +16,32 @@ def my_custom_tool(search_query: str, generate_image: bool = False) -> str:
|
|
16 |
search_query: The search query to look up
|
17 |
generate_image: Whether to also generate an image based on the search results
|
18 |
"""
|
|
|
|
|
19 |
try:
|
20 |
# Initialize the search tool
|
21 |
search_tool = DuckDuckGoSearchTool()
|
|
|
22 |
|
23 |
-
# Perform the search
|
24 |
-
print(f"Searching for: {search_query}")
|
25 |
results = search_tool(search_query)
|
26 |
-
print(f"
|
27 |
|
28 |
if not results:
|
29 |
return "No results found for the query."
|
30 |
|
31 |
-
# Get the first result
|
32 |
first_result = results[0]
|
33 |
-
summary = f"Latest AI News:\nTitle: {first_result['title']}\nSummary: {first_result['snippet']}"
|
34 |
-
|
35 |
-
# Add image generation if requested
|
36 |
-
if generate_image:
|
37 |
-
try:
|
38 |
-
print("Attempting to generate image...")
|
39 |
-
image_result = image_generation_tool(search_query)
|
40 |
-
summary += f"\n\nGenerated visualization based on the query."
|
41 |
-
except Exception as e:
|
42 |
-
print(f"Image generation failed: {str(e)}")
|
43 |
-
summary += f"\n\nNote: Image generation was requested but failed."
|
44 |
|
45 |
-
return
|
|
|
|
|
46 |
|
47 |
except Exception as e:
|
48 |
-
|
49 |
-
print(
|
50 |
-
return
|
|
|
51 |
|
52 |
@tool
|
53 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -86,7 +80,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
86 |
|
87 |
agent = CodeAgent(
|
88 |
model=model,
|
89 |
-
tools=[
|
90 |
max_steps=6,
|
91 |
verbosity_level=1,
|
92 |
grammar=None,
|
|
|
16 |
search_query: The search query to look up
|
17 |
generate_image: Whether to also generate an image based on the search results
|
18 |
"""
|
19 |
+
print("my_custom_tool called with query:", search_query) # Debug print
|
20 |
+
|
21 |
try:
|
22 |
# Initialize the search tool
|
23 |
search_tool = DuckDuckGoSearchTool()
|
24 |
+
print("DuckDuckGoSearchTool initialized") # Debug print
|
25 |
|
26 |
+
# Perform the search
|
|
|
27 |
results = search_tool(search_query)
|
28 |
+
print(f"Search returned {len(results) if results else 0} results") # Debug print
|
29 |
|
30 |
if not results:
|
31 |
return "No results found for the query."
|
32 |
|
33 |
+
# Get the first result
|
34 |
first_result = results[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
# Use final_answer to return the result
|
37 |
+
result_text = f"Latest AI News:\n{first_result['title']}\n{first_result['snippet']}"
|
38 |
+
return result_text
|
39 |
|
40 |
except Exception as e:
|
41 |
+
error_message = f"Error in my_custom_tool: {str(e)}"
|
42 |
+
print(error_message) # Debug print
|
43 |
+
return error_message
|
44 |
+
|
45 |
|
46 |
@tool
|
47 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
80 |
|
81 |
agent = CodeAgent(
|
82 |
model=model,
|
83 |
+
tools=[my_custom_tool, final_answer], ## add your tools here (don't remove final answer)
|
84 |
max_steps=6,
|
85 |
verbosity_level=1,
|
86 |
grammar=None,
|