File size: 1,446 Bytes
87b4224 43ae5be 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 = 'Retrieve existing YouTube transcript text and timestamped segments by video ID and language. Automatic captions are selected by default. Defaults to existing English automatic captions. No speech recognition, translation or fallback to another track; unavailable 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})
|