File size: 1,504 Bytes
87b4224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from smolagents import Tool


class FlashDataTool(Tool):
    name = 'youtube_transcript'
    description = 'Give a research agent timestamped text from an existing YouTube caption track. Keep segment start and end times so a reader can return to the video when checking a generated summary. Defaults to existing automatic English captions. No ASR, translation or automatic fallback to another language or caption source. Missing tracks fail. Uses paid FlashData API credits. Never automatically retry an uncertain submission; check Jobs first.'
    inputs = {'auto': {'description': 'True requests automatic captions; false requests manually authored '
                             'captions. Default: True.',
              'nullable': True,
              'type': 'boolean'},
     'language': {'description': 'Requested caption language code. pattern: ^[A-Za-z0-9-]{1,35}$. '
                                 "Default: 'en'.",
                  'nullable': True,
                  'type': 'string'},
     'video_id': {'description': '11-character YouTube video ID or a YouTube video URL.',
                  'type': 'string'}}
    output_type = 'object'

    def forward(self, video_id: str, language: str = 'en', auto: bool = True) -> dict:
        from langchain_flashdata import FlashDataYouTubeTranscript
        values = {'video_id': video_id, 'language': language, 'auto': auto}
        return FlashDataYouTubeTranscript().invoke({key: value for key, value in values.items() if value is not None})