| import datetime |
| import pytz |
| from smolagents import Tool, CodeAgent, ToolCallingAgent, LiteLLMModel, PythonInterpreterTool, tool, DuckDuckGoSearchTool |
| from langchain_community.document_loaders import YoutubeLoader |
| import re |
| import requests |
| from markdownify import markdownify |
| from requests.exceptions import RequestException |
|
|
| |
| @tool |
| def visit_webpage(url: str) -> str: |
| """Visits a webpage at the given URL and returns its content as a markdown string. |
| Args: |
| url: The URL of the webpage to visit. |
| Returns: |
| The content of the webpage converted to Markdown, or an error message if the request fails. |
| """ |
| try: |
| response = requests.get(url) |
| response.raise_for_status() |
|
|
| markdown_content = markdownify(response.text).strip() |
|
|
| markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content) |
|
|
| return markdown_content |
|
|
| except RequestException as e: |
| return f"Error fetching the webpage: {str(e)}" |
| except Exception as e: |
| return f"An unexpected error occurred: {str(e)}" |
|
|
|
|
| |
| @tool |
| def youtube_transcription_tool(url: str) -> str: |
| """ |
| This tool returns transcript of the youtube video. |
| Args: |
| url: youtube video url |
| """ |
| loader = YoutubeLoader.from_youtube_url( |
| url, add_video_info=False |
| ) |
| return loader.load()[0].page_content |