File size: 932 Bytes
a65b01c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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