Mightypeacock's picture
Upload tool
a65b01c verified
raw
history blame contribute delete
932 Bytes
from smolagents.tools import Tool
import requests
class VisitWebpageMDTool(Tool):
name = "visit_webpage_markdown"
description = "Visits a webpage at the given url and reads its content as a markdown document via Jina. Use this to browse webpages. It skips images / medias"
inputs = {'url': {'type': 'string', 'description': 'The url of the webpage to visit.'}}
output_type = "string"
def forward(self, url: str) -> str:
import requests
try:
# Send a GET request to the URL
response = requests.get('https://r.jina.ai/' +url)
response.raise_for_status() # Raise an exception for bad status codes
markdown_content =response.text.strip()
return markdown_content
except Exception as e:
return f"An unexpected error occurred: {str(e)}"
def __init__(self, *args, **kwargs):
self.is_initialized = False