Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
6278ff0f
Unverified
Commit
6278ff0f
authored
Feb 05, 2024
by
Yeuoly
Committed by
GitHub
Feb 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feat/add bing search (#2379)
parent
56c25bfb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
11 deletions
+64
-11
bing_web_search.py
...core/tools/provider/builtin/bing/tools/bing_web_search.py
+24
-10
bing_web_search.yaml
...re/tools/provider/builtin/bing/tools/bing_web_search.yaml
+40
-1
No files found.
api/core/tools/provider/builtin/bing/tools/bing_web_search.py
View file @
6278ff0f
...
...
@@ -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"]}'
))
return
results
\ No newline at end of file
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\n
Related 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
))
api/core/tools/provider/builtin/bing/tools/bing_web_search.yaml
View file @
6278ff0f
...
...
@@ -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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment