BrightData commited on
Commit
8bb17bf
·
verified ·
1 Parent(s): fc420de

Add Bright Data Search Tool

Browse files
Files changed (1) hide show
  1. tool.py +18 -5
tool.py CHANGED
@@ -1,8 +1,8 @@
1
  from typing import Any, Optional
2
  from smolagents.tools import Tool
 
3
  import json
4
  import requests
5
- import os
6
 
7
  class BrightDataSearchTool(Tool):
8
  name = "brightdata_search_engine"
@@ -11,9 +11,25 @@ class BrightDataSearchTool(Tool):
11
  Returns search results with URLs, titles, and descriptions.
12
  Ideal for gathering current information and news.
13
  """
14
- inputs = {'query': {'type': 'string', 'description': 'The search query'}, 'engine': {'type': 'string', 'description': "Search engine to use: 'google', 'bing', or 'yandex'. Default is 'google'", 'nullable': True, 'default': 'google'}}
15
  output_type = "string"
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def forward(self, query: str, engine: str = "google") -> str:
18
  """
19
  Search using Bright Data's search API.
@@ -78,6 +94,3 @@ class BrightDataSearchTool(Tool):
78
 
79
  except requests.exceptions.RequestException as e:
80
  return json.dumps({"error": str(e)})
81
-
82
- def __init__(self, *args, **kwargs):
83
- self.is_initialized = False
 
1
  from typing import Any, Optional
2
  from smolagents.tools import Tool
3
+ import os
4
  import json
5
  import requests
 
6
 
7
  class BrightDataSearchTool(Tool):
8
  name = "brightdata_search_engine"
 
11
  Returns search results with URLs, titles, and descriptions.
12
  Ideal for gathering current information and news.
13
  """
 
14
  output_type = "string"
15
 
16
+ def __init__(self):
17
+ # Build inputs at init to satisfy smolagents validation rules.
18
+ self.inputs = {
19
+ "query": {
20
+ "type": "string",
21
+ "description": "The search query",
22
+ },
23
+ "engine": {
24
+ "type": "string",
25
+ "description": "Search engine to use",
26
+ "enum": ["google", "bing", "yandex"],
27
+ "nullable": True,
28
+ "default": "google",
29
+ },
30
+ }
31
+ super().__init__()
32
+
33
  def forward(self, query: str, engine: str = "google") -> str:
34
  """
35
  Search using Bright Data's search API.
 
94
 
95
  except requests.exceptions.RequestException as e:
96
  return json.dumps({"error": str(e)})