Download tools/validate_url.py from aliroya32/ContiAI: direct link, hf CLI and curl.
- Browser
- Download file 917 Bytes
-
https://huggingface.co/spaces/aliroya32/ContiAI/resolve/main/tools/validate_url.py
- Command line
-
hf download hf://spaces/aliroya32/ContiAI/tools/validate_url.py
-
curl -L -o validate_url.py https://huggingface.co/spaces/aliroya32/ContiAI/resolve/main/tools/validate_url.py
917 Bytes
| from crewai.tools import BaseTool | |
| from typing import Literal | |
| import requests | |
| class URLValidatorTool(BaseTool): | |
| name: Literal["url_validator"] | |
| description : str = "Validate whether a given URL is reachable and returns a valid HTTP status." | |
| def _run(self, url: str) -> dict: | |
| """Synchronous tool execution""" | |
| try: | |
| response = requests.head(url, allow_redirects=True, timeout=15) | |
| return { | |
| "url": url, | |
| "status_code": response.status_code, | |
| "ok": response.status_code < 400 | |
| } | |
| except Exception as e: | |
| return { | |
| "url": url, | |
| "status_code": None, | |
| "ok": False, | |
| "error": str(e) | |
| } | |
| async def _arun(self, url: str) -> dict: | |
| """Asynchronous tool execution (not used but required)""" | |
| return self._run(url) | |