You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a tool to do it with a browser, but that's over kill for a lot of usecases.
Use Cases
Any content that isn't JS
Proposed API Interface
classGetUrlContent(BaseTool):
def__init__(self, name="get_url_content"):
super().__init__()
self.name=name@propertydefdefinition(self):
return {
"type": "function",
"function": {
"name": self.name,
"description": "Fetches the text content of a given URL. This tool makes a simple GET request and returns the raw text content. It does not render JavaScript or handle complex interactions.",
"parameters": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "The URL to fetch content from (e.g., 'https://www.example.com')."
}
},
"required": ["url"]
}
}
}
deffn(self, url: str):
logger.debug(f"Attempting to fetch content from URL: {url}")
try:
# Add a User-Agent header to mimic a browser, which can help with some sites headers= {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
# Add a timeout to prevent the request from hanging indefinitely response=requests.get(url, headers=headers, timeout=15)
response.raise_for_status() # This will raise an HTTPError for bad responses (4xx or 5xx) logger.info(f"Successfully fetched content from URL: {url}")
returnresponse.textexceptrequests.exceptions.HTTPErrorashttp_err:
logger.error(f"HTTP error occurred while fetching URL {url}: {http_err}")
returnf"Error: HTTP error occurred - {http_err}"exceptrequests.exceptions.ConnectionErrorasconn_err:
logger.error(f"Connection error occurred while fetching URL {url}: {conn_err}")
returnf"Error: Connection error occurred - {conn_err}"exceptrequests.exceptions.Timeoutastimeout_err:
logger.error(f"Timeout occurred while fetching URL {url}: {timeout_err}")
returnf"Error: Timeout occurred while fetching URL - {timeout_err}"exceptrequests.exceptions.RequestExceptionasreq_err:
logger.error(f"An error occurred during the request to URL {url}: {req_err}")
returnf"Error: An error occurred during the request - {req_err}"exceptExceptionase:
logger.error(f"An unexpected error occurred while fetching URL {url}: {e}")
returnf"Error: An unexpected error occurred - {e}"
Dependencies
requests
Documentation
docs/web/? Dealers choice
Additional Context
Add any other context or screenshots about the function proposal here.
Function Proposal
Description
We have a tool to do it with a browser, but that's over kill for a lot of usecases.
Use Cases
Any content that isn't JS
Proposed API Interface
Dependencies
requests
Documentation
docs/web/
? Dealers choiceAdditional Context
Add any other context or screenshots about the function proposal here.
Contribution Checklist
Development Plan
Outline your plan for implementing this function, including:
The text was updated successfully, but these errors were encountered: