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)}'