mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 03:32:23 +08:00
Feat/add bing search (#2379)
This commit is contained in:
parent
56c25bfb78
commit
6278ff0f30
|
@ -28,6 +28,9 @@ class BingSearchTool(BuiltinTool):
|
|||
if not query:
|
||||
raise Exception('query is required')
|
||||
|
||||
limit = min(tool_parameters.get('limit', 5), 10)
|
||||
result_type = tool_parameters.get('result_type', 'text') or 'text'
|
||||
|
||||
market = tool_parameters.get('market', 'US')
|
||||
lang = tool_parameters.get('language', 'en')
|
||||
|
||||
|
@ -49,13 +52,24 @@ class BingSearchTool(BuiltinTool):
|
|||
raise Exception(f'Error {response.status_code}: {response.text}')
|
||||
|
||||
response = response.json()
|
||||
# get the first 5 results
|
||||
search_results = response['webPages']['value'][:5]
|
||||
results = []
|
||||
for result in search_results:
|
||||
results.append(self.create_text_message(
|
||||
text=f'{result["name"]}: {result["url"]}'
|
||||
))
|
||||
search_results = response['webPages']['value'][:limit]
|
||||
|
||||
return results
|
||||
if result_type == 'link':
|
||||
results = []
|
||||
for result in search_results:
|
||||
results.append(self.create_text_message(
|
||||
text=f'{result["name"]}: {result["url"]}'
|
||||
))
|
||||
|
||||
return results
|
||||
else:
|
||||
# construct text
|
||||
text = ''
|
||||
for i, result in enumerate(search_results):
|
||||
text += f'{i+1}: {result["name"]} - {result["snippet"]}\n'
|
||||
|
||||
text += '\n\nRelated Searches:\n'
|
||||
for related in response['relatedSearches']['value']:
|
||||
text += f'{related["displayText"]} - {related["webSearchUrl"]}\n'
|
||||
|
||||
return self.create_text_message(text=self.summary(user_id=user_id, content=text))
|
||||
|
|
|
@ -15,6 +15,7 @@ parameters:
|
|||
- name: query
|
||||
type: string
|
||||
required: true
|
||||
form: llm
|
||||
label:
|
||||
en_US: Query string
|
||||
zh_Hans: 查询语句
|
||||
|
@ -24,7 +25,45 @@ parameters:
|
|||
zh_Hans: 用于搜索网页内容
|
||||
pt_BR: used for searching
|
||||
llm_description: key words for searching
|
||||
form: llm
|
||||
- name: limit
|
||||
type: number
|
||||
required: false
|
||||
form: form
|
||||
label:
|
||||
en_US: Limit for results length
|
||||
zh_Hans: 返回长度限制
|
||||
pt_BR: Limit for results length
|
||||
human_description:
|
||||
en_US: limit the number of results
|
||||
zh_Hans: 限制返回结果的数量
|
||||
pt_BR: limit the number of results
|
||||
min: 1
|
||||
max: 10
|
||||
default: 5
|
||||
- name: result_type
|
||||
type: select
|
||||
required: false
|
||||
label:
|
||||
en_US: result type
|
||||
zh_Hans: 结果类型
|
||||
pt_BR: result type
|
||||
human_description:
|
||||
en_US: return a list of links or texts
|
||||
zh_Hans: 返回一个连接列表还是纯文本内容
|
||||
pt_BR: return a list of links or texts
|
||||
default: text
|
||||
options:
|
||||
- value: link
|
||||
label:
|
||||
en_US: Link
|
||||
zh_Hans: 链接
|
||||
pt_BR: Link
|
||||
- value: text
|
||||
label:
|
||||
en_US: Text
|
||||
zh_Hans: 文本
|
||||
pt_BR: Text
|
||||
form: form
|
||||
- name: market
|
||||
type: select
|
||||
label:
|
||||
|
|
Loading…
Reference in New Issue
Block a user