|
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: |
|
|
|
response = requests.get('https://r.jina.ai/' +url) |
|
response.raise_for_status() |
|
|
|
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 |
|
|
|
|