File size: 812 Bytes
aa84f48
 
6442393
aa84f48
 
 
 
 
 
 
 
 
 
6442393
aa84f48
6442393
aa84f48
 
 
 
6442393
aa84f48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from smolagents import Tool
from llama_index.readers.youtube_transcript import YoutubeTranscriptReader

class YouTubeTranscript(Tool):
    name = 'youtube_transcript'
    description = "a tool that returns a transcript for a youtube video. Youtube videos come from urls containing www.youtube.com"
    inputs = {
        "url": {
            "type": "string",
            "description": "url to the youtube video, has 'www.youtube.com' in it."
        }
    }
    output_type = "string"

    def forward(self, url: str) -> str:
        try:
            loader = YoutubeTranscriptReader()
            documents = loader.load_data(ytlinks=[url])
            transcript = documents[0].text
            return transcript
        except Exception as e:
            return f'Error getting youtube transcript: {str(e)}'