File size: 2,172 Bytes
7514349 7953e73 7514349 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | from smolagents import Tool
class FlashDataTool(Tool):
name = 'google_search'
description = 'Search Google and return ranked titles, URLs, snippets and positions as JSON. Filter by country, language, location or date, and request additional pages. Returns search results, not webpage full text. Uses paid FlashData API credits. Never automatically retry an uncertain submission; check Jobs first.'
inputs = {'autocorrect': {'description': 'Autocorrect. Default: True.', 'nullable': True, 'type': 'boolean'},
'gl': {'description': 'Two-letter country code, for example us. pattern: ^[A-Za-z]{2}$. Default: '
'None.',
'nullable': True,
'type': 'string'},
'hl': {'description': 'Interface language code, for example en. pattern: ^[A-Za-z0-9-]{1,35}$. '
'Default: None.',
'nullable': True,
'type': 'string'},
'location': {'description': 'Optional geographic search location. Default: None.',
'nullable': True,
'type': 'string'},
'num': {'description': 'Num. minimum: 1. maximum: 100. Default: 10.',
'nullable': True,
'type': 'integer'},
'page': {'description': 'Page. minimum: 1. maximum: 100. Default: 1.',
'nullable': True,
'type': 'integer'},
'query': {'description': 'Search query, between 1 and 2,000 characters.', 'type': 'string'},
'tbs': {'description': 'Optional Google time filter, for example qdr:w. Default: None.',
'nullable': True,
'type': 'string'}}
output_type = 'object'
def forward(self, query: str, num: int = 10, page: int = 1, autocorrect: bool = True, gl: str | None = None, hl: str | None = None, location: str | None = None, tbs: str | None = None) -> dict:
from langchain_flashdata import FlashDataGoogleSearch
values = {'query': query, 'num': num, 'page': page, 'autocorrect': autocorrect, 'gl': gl, 'hl': hl, 'location': location, 'tbs': tbs}
return FlashDataGoogleSearch().invoke({key: value for key, value in values.items() if value is not None})
|