+7
register_tools.py
+7
register_tools.py
···
19
19
from tools.ignore import ignore_notification, IgnoreNotificationArgs
20
20
from tools.whitewind import create_whitewind_blog_post, WhitewindPostArgs
21
21
from tools.ack import annotate_ack, AnnotateAckArgs
22
+
from tools.webpage import fetch_webpage, WebpageArgs
22
23
23
24
load_dotenv()
24
25
logging.basicConfig(level=logging.INFO)
···
111
112
"args_schema": AnnotateAckArgs,
112
113
"description": "Add a note to the acknowledgment record for the current post interaction",
113
114
"tags": ["acknowledgment", "note", "annotation", "metadata"]
115
+
},
116
+
{
117
+
"func": fetch_webpage,
118
+
"args_schema": WebpageArgs,
119
+
"description": "Fetch a webpage and convert it to markdown/text format using Jina AI reader",
120
+
"tags": ["web", "fetch", "webpage", "markdown", "jina"]
114
121
},
115
122
]
116
123
+44
tools/webpage.py
+44
tools/webpage.py
···
1
+
"""Webpage fetch tool using Jina AI reader."""
2
+
from typing import Optional
3
+
from pydantic import BaseModel, Field
4
+
5
+
6
+
class 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
+
13
+
def 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
+
import logging
25
+
26
+
logger = logging.getLogger(__name__)
27
+
28
+
try:
29
+
# Construct the Jina AI reader URL
30
+
jina_url = f"https://r.jina.ai/{url}"
31
+
32
+
# Make the request to Jina AI
33
+
response = requests.get(jina_url, timeout=30)
34
+
response.raise_for_status()
35
+
36
+
logger.info(f"Successfully fetched webpage: {url}")
37
+
return response.text
38
+
39
+
except requests.exceptions.RequestException as e:
40
+
logger.error(f"Error fetching webpage {url}: {e}")
41
+
raise Exception(f"Error fetching webpage: {str(e)}")
42
+
except Exception as e:
43
+
logger.error(f"Unexpected error fetching webpage {url}: {e}")
44
+
raise Exception(f"Unexpected error: {str(e)}")