File size: 1,377 Bytes
76df15d
 
 
 
 
13fc636
76df15d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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


class FlashDataTool(Tool):
    name = 'youtube_captions'
    description = 'Retrieve existing uploader-provided YouTube captions by video ID and language. Get subtitle text and timestamped segments for local processing or export. Defaults to existing English manual captions. Does not generate or translate subtitles, or fall back to another track. Uses paid FlashData API credits. Never automatically retry an uncertain submission; check Jobs first.'
    inputs = {'auto': {'description': 'False selects manual; true automatic captions. Default: False.',
              '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 = False) -> dict:
        from langchain_flashdata import FlashDataYouTubeCaptions
        values = {'video_id': video_id, 'language': language, 'auto': auto}
        return FlashDataYouTubeCaptions().invoke({key: value for key, value in values.items() if value is not None})