Spaces:
Build error
Build error
Download tools/search_tool.py from sp103107/agent-system: direct link, hf CLI and curl.
- Browser
- Download file 901 Bytes
-
https://huggingface.co/spaces/sp103107/agent-system/resolve/main/tools/search_tool.py
- Command line
-
hf download hf://spaces/sp103107/agent-system/tools/search_tool.py
-
curl -L -o search_tool.py https://huggingface.co/spaces/sp103107/agent-system/resolve/main/tools/search_tool.py
901 Bytes
| from duckduckgo_search import ddg | |
| import logging | |
| from datetime import datetime | |
| logger = logging.getLogger(__name__) | |
| class SearchTool: | |
| def __init__(self): | |
| self.max_results = 10 | |
| def search(self, query, max_results=None): | |
| """Perform a DuckDuckGo search""" | |
| try: | |
| results = ddg(query, max_results=max_results or self.max_results) | |
| return [{ | |
| "title": result["title"], | |
| "link": result["link"], | |
| "snippet": result["snippet"], | |
| "timestamp": datetime.now().isoformat() | |
| } for result in results] | |
| except Exception as e: | |
| logger.error(f"Search failed: {str(e)}") | |
| raise | |
| # Singleton instance | |
| _instance = None | |
| def get_search_tool(): | |
| global _instance | |
| if _instance is None: | |
| _instance = SearchTool() | |
| return _instance |