web_browser
Module Contents
Classes
Create a SearXNG client. |
|
Wrapper around the Brave Search API. |
|
Wrapper around the Serper.dev Google Search API. |
|
Wrapper around the tencentclound Search API. |
|
Wrapper around the Web Browser Tool. |
|
Wrapper around the Web Browser Tool. |
- class lagent.actions.web_browser.BaseSearch(topk=3, black_list=None)
- 参数:
topk (int) –
black_list (List[str]) –
- topk = 3
- black_list = None
- class lagent.actions.web_browser.DuckDuckGoSearch(topk=3, black_list=['enoN', 'youtube.com', 'bilibili.com', 'researchgate.net'], **kwargs)
Bases:
BaseSearch- 参数:
topk (int) –
black_list (List[str]) –
- proxy
- timeout
- search(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- async asearch(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- class lagent.actions.web_browser.BingSearch(api_key, region='zh-CN', topk=3, black_list=['enoN', 'youtube.com', 'bilibili.com', 'researchgate.net'], **kwargs)
Bases:
BaseSearch- 参数:
api_key (str) –
region (str) –
topk (int) –
black_list (List[str]) –
- api_key
- market = 'zh-CN'
- proxy
- search(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- async asearch(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- class lagent.actions.web_browser.SearxngSearch(api_key='sk-xxxx', auth_name='searxng', language='zh', categories='general', url='http://127.0.0.1:18883', topk=3, black_list=['enoN', 'youtube.com', 'bilibili.com', 'researchgate.net'], **kwargs)
Bases:
BaseSearchCreate a SearXNG client. (PS: 1. First, set up your own SearXNG search engine server: https://docs.searxng.org/
- For servers like SearXNG that do not require an apiKey,
you don’t need to concern yourself with auth_name and api_key.
For servers that require passing an apiKey, auth_name would be the key in the header, and api_key would be the value.
Note that custom parameters are not yet supported for input.
- For SearXNG-like search engine servers that do not require authentication:
- You need to set the server address in one of two ways:
Method One: Environment variable: export SEARXNG_URL=”http://192.168.26.xxx:18080/search” Method Two: Assign the URL when initializing SearxngSearch: tool = SearxngSearch(url=””) If both methods are used, the value from method one takes precedence.
- For search engine servers that require authentication:
Omitted
- 参数:
api_key (str) – API key, default is ‘sk-xxxx’.
auth_name (str) – Authentication name, default is ‘searxng’.
language (str) – Language setting, default is ‘zh’.
categories (str) – Category setting, default is ‘general’.
url (str) – URL of the SearXNG service, default is ‘http://127.0.0.1:18883’.
topk (int) – Number of top results to return, default is 3.
black_list (List[str]) – Blacklist of domains you do not wish to see in search results.
**kwargs – Other variable keyword arguments, such as proxy settings.
- api_key = 'sk-xxxx'
- auth_name = 'searxng'
- language = 'zh'
- categories = 'general'
- proxy
- SEARXNG_URL
- search(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- async asearch(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- class lagent.actions.web_browser.BraveSearch(api_key, region='ALL', language='zh-hans', extra_snippests=True, topk=3, black_list=['enoN', 'youtube.com', 'bilibili.com', 'researchgate.net'], **kwargs)
Bases:
BaseSearchWrapper around the Brave Search API.
To use, you should pass your Brave Search API key to the constructor.
- 参数:
api_key (str) – API KEY to use Brave Search API. You can create a free API key at https://api.search.brave.com/app/keys.
search_type (str) – Brave Search API supports [‘web’, ‘news’, ‘images’, ‘videos’], currently only supports ‘news’ and ‘web’.
topk (int) – The number of search results returned in response from API search results.
region (str) – The country code string. Specifies the country where the search results come from.
language (str) – The language code string. Specifies the preferred language for the search results.
extra_snippets (bool) – Allows retrieving up to 5 additional snippets, which are alternative excerpts from the
results. (search) –
**kwargs – Any other parameters related to the Brave Search API. Find more details at https://api.search.brave.com/app/documentation/web-search/get-started.
extra_snippests (bool) –
black_list (List[str]) –
- api_key
- market = 'ALL'
- proxy
- language = 'zh-hans'
- extra_snippests = True
- search_type
- kwargs
- search(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- async asearch(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- class lagent.actions.web_browser.GoogleSearch(api_key, topk=3, black_list=['enoN', 'youtube.com', 'bilibili.com', 'researchgate.net'], **kwargs)
Bases:
BaseSearchWrapper around the Serper.dev Google Search API.
To use, you should pass your serper API key to the constructor.
- 参数:
api_key (str) – API KEY to use serper google search API. You can create a free API key at https://serper.dev.
search_type (str) – Serper API supports [‘search’, ‘images’, ‘news’, ‘places’] types of search, currently we only support ‘search’ and ‘news’.
topk (int) – The number of search results returned in response from api search results.
**kwargs – Any other parameters related to the Serper API. Find more details at https://serper.dev/playground
black_list (List[str]) –
- result_key_for_type
- api_key
- proxy
- search_type
- kwargs
- search(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- async asearch(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- class lagent.actions.web_browser.TencentSearch(secret_id='Your SecretId', secret_key='Your SecretKey', api_key='', action='SearchCommon', version='2020-12-29', service='tms', host='tms.tencentcloudapi.com', topk=3, tsn=None, insite=None, category=None, vrid=None, black_list=['enoN', 'youtube.com', 'bilibili.com', 'researchgate.net'])
Bases:
BaseSearchWrapper around the tencentclound Search API.
To use, you should pass your secret_id and secret_key to the constructor.
- 参数:
secret_id (str) – Your Tencent Cloud secret ID for accessing the API. For more details, refer to the documentation: https://cloud.tencent.com/document/product/598/40488.
secret_key (str) – Your Tencent Cloud secret key for accessing the API.
api_key (str, optional) – Additional API key, if required.
action (str) – The action for this interface, use SearchCommon.
version (str) – The API version, use 2020-12-29.
service (str) – The service name, use tms.
host (str) – The API host, use tms.tencentcloudapi.com.
topk (int) – The maximum number of search results to return.
tsn (int) – Time filter for search results. Valid values: 1 (within 1 day), 2 (within 1 week), 3 (within 1 month), 4 (within 1 year), 5 (within 6 months), 6 (within 3 years).
insite (str) – Specify a site to search within (supports only a single site). If not specified, the entire web is searched. Example: zhihu.com.
category (str) – Vertical category for filtering results. Optional values include: baike (encyclopedia), weather, calendar, medical, news, train, star (horoscope).
vrid (str) – Result card type(s). Different vrid values represent different types of result cards. Supports multiple values separated by commas. Example: 30010255.
black_list (List[str]) –
- secret_id = 'Your SecretId'
- secret_key = 'Your SecretKey'
- api_key = ''
- action = 'SearchCommon'
- version = '2020-12-29'
- service = 'tms'
- host = 'tms.tencentcloudapi.com'
- tsn = None
- insite = None
- category = None
- vrid = None
- search(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- async asearch(query, max_retry=3)
- 参数:
query (str) –
max_retry (int) –
- 返回类型:
dict
- class lagent.actions.web_browser.ContentFetcher(timeout=5)
- 参数:
timeout (int) –
- timeout = 5
- fetch(url)
- 参数:
url (str) –
- 返回类型:
Tuple[bool, str]
- async afetch(url)
- 参数:
url (str) –
- 返回类型:
Tuple[bool, str]
- class lagent.actions.web_browser.WebBrowser(searcher_type='DuckDuckGoSearch', timeout=5, black_list=['enoN', 'youtube.com', 'bilibili.com', 'researchgate.net'], topk=20, description=None, parser=JsonParser, **kwargs)
Bases:
lagent.actions.base_action.BaseActionWrapper around the Web Browser Tool.
- 参数:
searcher_type (str) –
timeout (int) –
black_list (Optional[List[str]]) –
topk (int) –
description (Optional[dict]) –
parser (Type[lagent.actions.parser.BaseParser]) –
- searcher
- fetcher
- search_results = None
- search(query)
BING search API :param query: list of search query strings :type query: List[str]
- 参数:
query (Union[str, List[str]]) –
- 返回类型:
dict
- select(select_ids)
get the detailed content on the selected pages.
- 参数:
select_ids (List[int]) – list of index to select. Max number of index to be selected is no more than 4.
- 返回类型:
dict
- open_url(url)
- 参数:
url (str) –
- 返回类型:
dict
- class lagent.actions.web_browser.AsyncWebBrowser(searcher_type='DuckDuckGoSearch', timeout=5, black_list=['enoN', 'youtube.com', 'bilibili.com', 'researchgate.net'], topk=20, description=None, parser=JsonParser, **kwargs)
Bases:
lagent.actions.base_action.AsyncActionMixin,WebBrowserWrapper around the Web Browser Tool.
- 参数:
searcher_type (str) –
timeout (int) –
black_list (Optional[List[str]]) –
topk (int) –
description (Optional[dict]) –
parser (Type[lagent.actions.parser.BaseParser]) –
- async search(query)
BING search API
- 参数:
query (List[str]) – list of search query strings
- 返回类型:
dict
- async select(select_ids)
get the detailed content on the selected pages.
- 参数:
select_ids (List[int]) – list of index to select. Max number of index to be selected is no more than 4.
- 返回类型:
dict
- async open_url(url)
- 参数:
url (str) –
- 返回类型:
dict