File size: 1,182 Bytes
6fccf23
 
 
 
 
a586e92
6fccf23
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from smolagents import Tool


class FlashDataTool(Tool):
    name = 'youtube_suggestions'
    description = 'Get YouTube autocomplete suggestions for a query prefix. Choose a language and region, and return the suggested search phrases. Suggestions are not search-volume estimates or popularity rankings. Uses paid FlashData API credits. Never automatically retry an uncertain submission; check Jobs first.'
    inputs = {'language': {'description': "Language. pattern: ^[A-Za-z0-9-]{1,35}$. Default: 'en'.",
                  'nullable': True,
                  'type': 'string'},
     'query': {'description': 'YouTube search prefix.', 'type': 'string'},
     'region': {'description': "Region. pattern: ^[A-Za-z]{2}$. Default: 'US'.",
                'nullable': True,
                'type': 'string'}}
    output_type = 'object'

    def forward(self, query: str, language: str = 'en', region: str = 'US') -> dict:
        from langchain_flashdata import FlashDataYouTubeSuggestions
        values = {'query': query, 'language': language, 'region': region}
        return FlashDataYouTubeSuggestions().invoke({key: value for key, value in values.items() if value is not None})