Feat: support json output for bing-search (#10904)
This commit is contained in:
parent
1a6b961b5f
commit
8c2f62fb92
2 changed files with 43 additions and 3 deletions
|
|
@ -66,6 +66,41 @@ class BingSearchTool(BuiltinTool):
|
||||||
results.append(self.create_text_message(text=f'{related.get("displayText", "")}{url}'))
|
results.append(self.create_text_message(text=f'{related.get("displayText", "")}{url}'))
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
elif result_type == "json":
|
||||||
|
result = {}
|
||||||
|
if search_results:
|
||||||
|
result["organic"] = [
|
||||||
|
{
|
||||||
|
"title": item.get("name", ""),
|
||||||
|
"snippet": item.get("snippet", ""),
|
||||||
|
"url": item.get("url", ""),
|
||||||
|
"siteName": item.get("siteName", ""),
|
||||||
|
}
|
||||||
|
for item in search_results
|
||||||
|
]
|
||||||
|
|
||||||
|
if computation and "expression" in computation and "value" in computation:
|
||||||
|
result["computation"] = {"expression": computation["expression"], "value": computation["value"]}
|
||||||
|
|
||||||
|
if entities:
|
||||||
|
result["entities"] = [
|
||||||
|
{
|
||||||
|
"name": item.get("name", ""),
|
||||||
|
"url": item.get("url", ""),
|
||||||
|
"description": item.get("description", ""),
|
||||||
|
}
|
||||||
|
for item in entities
|
||||||
|
]
|
||||||
|
|
||||||
|
if news:
|
||||||
|
result["news"] = [{"name": item.get("name", ""), "url": item.get("url", "")} for item in news]
|
||||||
|
|
||||||
|
if related_searches:
|
||||||
|
result["related searches"] = [
|
||||||
|
{"displayText": item.get("displayText", ""), "url": item.get("webSearchUrl", "")} for item in news
|
||||||
|
]
|
||||||
|
|
||||||
|
return self.create_json_message(result)
|
||||||
else:
|
else:
|
||||||
# construct text
|
# construct text
|
||||||
text = ""
|
text = ""
|
||||||
|
|
|
||||||
|
|
@ -113,9 +113,9 @@ parameters:
|
||||||
zh_Hans: 结果类型
|
zh_Hans: 结果类型
|
||||||
pt_BR: result type
|
pt_BR: result type
|
||||||
human_description:
|
human_description:
|
||||||
en_US: return a list of links or texts
|
en_US: return a list of links, json or texts
|
||||||
zh_Hans: 返回一个连接列表还是纯文本内容
|
zh_Hans: 返回一个列表,内容是链接、json还是纯文本
|
||||||
pt_BR: return a list of links or texts
|
pt_BR: return a list of links, json or texts
|
||||||
default: text
|
default: text
|
||||||
options:
|
options:
|
||||||
- value: link
|
- value: link
|
||||||
|
|
@ -123,6 +123,11 @@ parameters:
|
||||||
en_US: Link
|
en_US: Link
|
||||||
zh_Hans: 链接
|
zh_Hans: 链接
|
||||||
pt_BR: Link
|
pt_BR: Link
|
||||||
|
- value: json
|
||||||
|
label:
|
||||||
|
en_US: JSON
|
||||||
|
zh_Hans: JSON
|
||||||
|
pt_BR: JSON
|
||||||
- value: text
|
- value: text
|
||||||
label:
|
label:
|
||||||
en_US: Text
|
en_US: Text
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue