Spaces:
Runtime error
Runtime error
fixed ddgs tool
Browse files
app.py
CHANGED
|
@@ -27,15 +27,25 @@ def duckduckgo_search(query: str) -> str:
|
|
| 27 |
Returns:
|
| 28 |
A string containing the top 3 URLs separated by newline characters.
|
| 29 |
"""
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def generate_image(prompt: str) -> str:
|
|
|
|
| 27 |
Returns:
|
| 28 |
A string containing the top 3 URLs separated by newline characters.
|
| 29 |
"""
|
| 30 |
+
try:
|
| 31 |
+
# Initialize the search tool
|
| 32 |
+
search_tool = DuckDuckGoSearchTool()
|
| 33 |
+
# Run the search query
|
| 34 |
+
results = search_tool.run(query)
|
| 35 |
+
|
| 36 |
+
# Ensure results are a list
|
| 37 |
+
if not isinstance(results, list):
|
| 38 |
+
return "Unexpected response format from DuckDuckGo search."
|
| 39 |
+
|
| 40 |
+
# Extract the top 3 results
|
| 41 |
+
top_results = results[:3]
|
| 42 |
+
urls = [result.get("url", "URL not found") for result in top_results]
|
| 43 |
+
|
| 44 |
+
return "\n".join(urls)
|
| 45 |
|
| 46 |
+
except Exception as e:
|
| 47 |
+
return f"Error performing DuckDuckGo search: {str(e)}"
|
| 48 |
+
|
| 49 |
|
| 50 |
@tool
|
| 51 |
def generate_image(prompt: str) -> str:
|