Spaces:
Build error
Build error
Download tools/base_tool_template.py from sp103107/agent-system: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/sp103107/agent-system/resolve/main/tools/base_tool_template.py
- Command line
-
hf download hf://spaces/sp103107/agent-system/tools/base_tool_template.py
-
curl -L -o base_tool_template.py https://huggingface.co/spaces/sp103107/agent-system/resolve/main/tools/base_tool_template.py
1.69 kB
| from duckduckgo_search import DDGS | |
| import json | |
| from typing import Dict, List, Any | |
| from datetime import datetime | |
| import requests | |
| import os | |
| def process_request(input_data: Dict[str, Any]) -> Dict[str, Any]: | |
| """ | |
| Base tool template for processing requests | |
| Args: | |
| input_data: The input request data | |
| Returns: | |
| Dict containing results and metadata | |
| """ | |
| try: | |
| requirements = input_data.get('task', {}).get('requirements', {}) | |
| search_params = {search_params_logic} # type: ignore | |
| results = [] | |
| with DDGS() as ddgs: | |
| web_results = list(ddgs.text( | |
| keywords=search_params.get('query', ''), | |
| max_results=search_params.get('max_results', 5), | |
| region='wt-wt', | |
| safesearch='moderate' | |
| )) | |
| for r in web_results: | |
| results.append({ | |
| 'title': r.get('title', ''), | |
| 'link': r.get('link', ''), | |
| 'snippet': r.get('body', ''), | |
| 'source': 'web' | |
| }) | |
| return { | |
| 'status': 'success', | |
| 'results': results, | |
| 'metadata': { | |
| 'source': '{tool_name}', | |
| 'timestamp': datetime.now().isoformat(), | |
| 'query': search_params | |
| } | |
| } | |
| except Exception as e: | |
| return { | |
| 'status': 'error', | |
| 'error': str(e), | |
| 'metadata': { | |
| 'source': '{tool_name}' | |
| } | |
| } | |
| # Set result for tool execution | |
| result = process_request(input_data) # type: ignore |