Skip to content

Feat: support json output for bing-search #10904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions api/core/tools/provider/builtin/bing/tools/bing_web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@ def _invoke_bing(
results.append(self.create_text_message(text=f'{related.get("displayText", "")}{url}'))

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:
# construct text
text = ""
Expand Down
11 changes: 8 additions & 3 deletions api/core/tools/provider/builtin/bing/tools/bing_web_search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,21 @@ parameters:
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
en_US: return a list of links, json or texts
zh_Hans: 返回一个列表,内容是链接、json还是纯文本
pt_BR: return a list of links, json or texts
default: text
options:
- value: link
label:
en_US: Link
zh_Hans: 链接
pt_BR: Link
- value: json
label:
en_US: JSON
zh_Hans: JSON
pt_BR: JSON
- value: text
label:
en_US: Text
Expand Down