Spaces:
Sleeping
Sleeping
def web_search(query: str) -> str: | |
"""Performs a DuckDuckGo search for the given query and returns the results. | |
Args: | |
query: The search query. | |
Returns: | |
The top search results as a string. | |
""" | |
try: | |
if not query or not query.strip(): | |
return "Error: Search query cannot be empty" | |
search_tool = DuckDuckGoSearchRun() | |
results = search_tool.invoke(query.strip()) | |
# Clean up the results a bit | |
if len(results) > 2000: # Truncate very long results | |
results = results[:2000] + "... (truncated)" | |
return results | |
except Exception as e: | |
return f"Error performing web search: {str(e)}" | |