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


class FlashDataTool(Tool):
    name = 'youtube_search_extended'
    description = 'Search YouTube for larger result sets, requesting up to 700 videos per query. Retrieve video IDs and available titles, channels, dates and durations. Default 20, maximum 700 requested results; fewer may be available. Extended Search has separate pricing and is not standard-search pagination. Uses paid FlashData API credits. Never automatically retry an uncertain submission; check Jobs first.'
    inputs = {'filters': {'description': 'Optional YouTube filters: duration, sort_by, type, upload_date and '
                                'boolean feature flags. See the input validation schema in the '
                                'documentation for supported values. Default: None.',
                 'nullable': True,
                 'type': 'object'},
     'max_results': {'description': 'Requested result limit, up to 700. minimum: 1. maximum: 700. '
                                    'Default: 20.',
                     'nullable': True,
                     'type': 'integer'},
     'query': {'description': 'YouTube search query, between 1 and 2,000 characters.',
               'type': 'string'}}
    output_type = 'object'

    def forward(self, query: str, max_results: int = 20, filters: dict | None = None) -> dict:
        from langchain_flashdata import FlashDataYouTubeExtendedSearch
        values = {'query': query, 'max_results': max_results, 'filters': filters}
        return FlashDataYouTubeExtendedSearch().invoke({key: value for key, value in values.items() if value is not None})