Final_Assignment_Template / tools /visit_webpage_tool.py
shreyassahu22's picture
Upload 10 files
4b58858 verified
Raw
History Blame Contribute Delete
340 Bytes
from langchain.tools import tool
import trafilatura
@tool
def visit_webpage(url: str) -> str:
"""Fetch and return the text content of a web page."""
downloaded = trafilatura.fetch_url(url)
if downloaded:
text = trafilatura.extract(downloaded) or ""
return text[:15000]
return "Error: could not fetch page"