File size: 1,376 Bytes
83a7d76
0c9dfc5
40c04fa
0c9dfc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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

# create tools here:
@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 #2
@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