a digital person for bluesky
at main 1.1 kB view raw
1"""Webpage fetch tool using Jina AI reader.""" 2from typing import Optional 3from pydantic import BaseModel, Field 4 5 6class WebpageArgs(BaseModel): 7 url: str = Field( 8 ..., 9 description="The URL of the webpage to fetch and convert to markdown/text format" 10 ) 11 12 13def fetch_webpage(url: str) -> str: 14 """ 15 Fetch a webpage and convert it to markdown/text format using Jina AI reader. 16 17 Args: 18 url: The URL of the webpage to fetch and convert 19 20 Returns: 21 String containing the webpage content in markdown/text format 22 """ 23 import requests 24 25 try: 26 # Construct the Jina AI reader URL 27 jina_url = f"https://r.jina.ai/{url}" 28 29 # Make the request to Jina AI 30 response = requests.get(jina_url, timeout=30) 31 response.raise_for_status() 32 33 return response.text 34 35 except requests.exceptions.RequestException as e: 36 raise Exception(f"Error fetching webpage: {str(e)}") 37 except Exception as e: 38 raise Exception(f"Unexpected error: {str(e)}")