File size: 2,351 Bytes
c4b829b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from langchain.tools import Tool
from youtube_transcript_api import YouTubeTranscriptApi, NoTranscriptFound, TranscriptsDisabled
import operator


def extract_youtube_transcript(youtube_url: str) -> str:
    """
    Extracts the transcript from a given YouTube video URL.
    Returns the transcript as a single string or an error message if not found.
    """
    try:
        video_id = youtube_url.split("v=")[1].split("&")[0]
        transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
        transcript = " ".join([item['text'] for item in transcript_list])
        return transcript
    except NoTranscriptFound:
        return "Error: No transcript found for this video. It might be disabled or not available in English."
    except TranscriptsDisabled:
        return "Error: Transcripts are disabled for this video."
    except Exception as e:
        return f"Error extracting transcript: {str(e)}"

youtube_transcript_tool = Tool(
    name="youtube_transcript_extractor",
    func=extract_youtube_transcript,
    description="Extracts the full transcript from a YouTube video given its URL. Input should be a valid YouTube video URL."
)

def add(a: float, b: float) -> float:
    """Adds two numbers."""
    return operator.add(a, b)

def subtract(a: float, b: float) -> float:
    """Subtracts the second number from the first."""
    return operator.sub(a, b)

def multiply(a: float, b: float) -> float:
    """Multiplies two numbers."""
    return operator.mul(a, b)

def divide(a: float, b: float) -> float:
    """Divides the first number by the second. Returns an error message if division by zero."""
    if b == 0:
        return "Error: Cannot divide by zero."
    return operator.truediv(a, b)

add_tool = Tool(
    name="calculator_add",
    func=add,
    description="Adds two numbers. Input should be two numbers (a, b)."
)

subtract_tool = Tool(
    name="calculator_subtract",
    func=subtract,
    description="Subtracts the second number from the first. Input should be two numbers (a, b)."
)

multiply_tool = Tool(
    name="calculator_multiply",
    func=multiply,
    description="Multiplies two numbers. Input should be two numbers (a, b)."
)

divide_tool = Tool(
    name="calculator_divide",
    func=divide,
    description="Divides the first number by the second. Input should be two numbers (a, b)."
)