Spaces:
Running
Running
from .tool import Tool | |
from markdownify import markdownify | |
import requests | |
class FetchTool(Tool): | |
def __init__(self): | |
super().__init__( | |
name="fetch", | |
description="Fetch the content of a URL and return the markdownified version of the content", | |
inputSchema={ | |
"type": "object", | |
"properties": { | |
"url": {"type": "string", "description": "The URL to fetch"} | |
} | |
} | |
) | |
def __call__(self, url: str): | |
try: | |
if not url: | |
return "Error: URL parameter is required" | |
resp = requests.get(url) | |
resp.raise_for_status() # Raise an exception for bad status codes | |
return markdownify(resp.text) | |
except requests.exceptions.RequestException as e: | |
return f"Error fetching URL: {str(e)}" | |
except Exception as e: | |
return f"Unexpected error while processing URL: {str(e)}" |