File size: 1,512 Bytes
bf24a77
 
 
 
 
fdd5719
bf24a77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_search'
    description = 'Search YouTube by keyword, upload date, duration and other filters. Return video IDs, titles, channels and available video statistics. Request 1–20 results; this adapter defaults to 10. Actual results may be fewer. Transcript retrieval is separate. 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 number of videos. minimum: 1. maximum: 20. Default: 10.',
                     '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 = 10, filters: dict | None = None) -> dict:
        from langchain_flashdata import FlashDataYouTubeSearch
        values = {'query': query, 'max_results': max_results, 'filters': filters}
        return FlashDataYouTubeSearch().invoke({key: value for key, value in values.items() if value is not None})