Create broadfield_search.py
Browse files- tools/broadfield_search.py +24 -0
tools/broadfield_search.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Optional
|
2 |
+
from smolagents.tools import Tool
|
3 |
+
from gradio_client import Client
|
4 |
+
|
5 |
+
class BroadfieldWebsearch(Tool):
|
6 |
+
client = Client("broadfield-dev/browser")
|
7 |
+
name = "web search by broadfield"
|
8 |
+
description = "Searches the web with common web search engines."
|
9 |
+
inputs = {'query': {'type': 'any', 'description': 'The query terms to use for the web search.'}}
|
10 |
+
output_type = "any"
|
11 |
+
|
12 |
+
def forward(self, query: Any) -> Any:
|
13 |
+
result = result = client.predict(
|
14 |
+
action="Search",
|
15 |
+
query=query,
|
16 |
+
browser_name="firefox",
|
17 |
+
search_engine_name="DuckDuckGo",
|
18 |
+
api_name="/web_browse"
|
19 |
+
)
|
20 |
+
|
21 |
+
return result['markdown_content']
|
22 |
+
|
23 |
+
def __init__(self, *args, **kwargs):
|
24 |
+
self.is_initialized = False
|