From 1b7e6c57057fdddb57c1585e10c9ad6ccf59e856 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Thu, 12 Mar 2026 17:11:05 -0700 Subject: [PATCH] Add the fetch_webpage tool source --- user_data/tools/fetch_webpage.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 user_data/tools/fetch_webpage.py diff --git a/user_data/tools/fetch_webpage.py b/user_data/tools/fetch_webpage.py new file mode 100644 index 00000000..e514491c --- /dev/null +++ b/user_data/tools/fetch_webpage.py @@ -0,0 +1,28 @@ +from modules.web_search import download_web_page, truncate_content_by_tokens + +tool = { + "type": "function", + "function": { + "name": "fetch_webpage", + "description": "Fetch and read the contents of a web page given its URL. Returns the page content as plain text.", + "parameters": { + "type": "object", + "properties": { + "url": {"type": "string", "description": "The URL of the web page to fetch."}, + }, + "required": ["url"] + } + } +} + + +def execute(arguments): + url = arguments.get("url", "") + if not url: + return {"error": "No URL provided."} + + content = download_web_page(url, include_links=True) + if not content or not content.strip(): + return {"error": f"Failed to fetch content from {url}"} + + return {"url": url, "content": truncate_content_by_tokens(content)}