瀏覽代碼

Feat/add bing search (#2379)

tags/0.5.4
Yeuoly 1 年之前
父節點
當前提交
6278ff0f30
No account linked to committer's email address

+ 24
- 10
api/core/tools/provider/builtin/bing/tools/bing_web_search.py 查看文件

if not query: if not query:
raise Exception('query is required') 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') market = tool_parameters.get('market', 'US')
lang = tool_parameters.get('language', 'en') lang = tool_parameters.get('language', 'en')


raise Exception(f'Error {response.status_code}: {response.text}') raise Exception(f'Error {response.status_code}: {response.text}')
response = response.json() 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"]}'
))

return results
search_results = response['webPages']['value'][:limit]

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))

+ 40
- 1
api/core/tools/provider/builtin/bing/tools/bing_web_search.yaml 查看文件

- name: query - name: query
type: string type: string
required: true required: true
form: llm
label: label:
en_US: Query string en_US: Query string
zh_Hans: 查询语句 zh_Hans: 查询语句
zh_Hans: 用于搜索网页内容 zh_Hans: 用于搜索网页内容
pt_BR: used for searching pt_BR: used for searching
llm_description: key words 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 - name: market
type: select type: select
label: label:

Loading…
取消
儲存