chore: update duckduckgo tool (#6983)

This commit is contained in:
非法操作 2024-08-06 10:16:04 +08:00 committed by GitHub
parent cba9319cc7
commit 312d905c9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 65 deletions

View File

@ -25,9 +25,9 @@ parameters:
type: select type: select
required: true required: true
options: options:
- value: gpt-3.5 - value: gpt-4o-mini
label: label:
en_US: GPT-3.5 en_US: GPT-4o-mini
- value: claude-3-haiku - value: claude-3-haiku
label: label:
en_US: Claude 3 en_US: Claude 3

View File

@ -21,23 +21,16 @@ class DuckDuckGoSearchTool(BuiltinTool):
""" """
Tool for performing a search using DuckDuckGo search engine. Tool for performing a search using DuckDuckGo search engine.
""" """
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage | list[ToolInvokeMessage]:
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage: query = tool_parameters.get('query')
query = tool_parameters.get('query', '') max_results = tool_parameters.get('max_results', 5)
result_type = tool_parameters.get('result_type', 'text')
max_results = tool_parameters.get('max_results', 10)
require_summary = tool_parameters.get('require_summary', False) require_summary = tool_parameters.get('require_summary', False)
response = DDGS().text(query, max_results=max_results) response = DDGS().text(query, max_results=max_results)
if result_type == 'link':
results = [f"[{res.get('title')}]({res.get('href')})" for res in response]
results = "\n".join(results)
return self.create_link_message(link=results)
results = [res.get("body") for res in response]
results = "\n".join(results)
if require_summary: if require_summary:
results = "\n".join([res.get("body") for res in response])
results = self.summary_results(user_id=user_id, content=results, query=query) results = self.summary_results(user_id=user_id, content=results, query=query)
return self.create_text_message(text=results) return self.create_text_message(text=results)
return [self.create_json_message(res) for res in response]
def summary_results(self, user_id: str, content: str, query: str) -> str: def summary_results(self, user_id: str, content: str, query: str) -> str:
prompt = SUMMARY_PROMPT.format(query=query, content=content) prompt = SUMMARY_PROMPT.format(query=query, content=content)

View File

@ -28,29 +28,6 @@ parameters:
label: label:
en_US: Max results en_US: Max results
zh_Hans: 最大结果数量 zh_Hans: 最大结果数量
human_description:
en_US: The max results.
zh_Hans: 最大结果数量
form: form
- name: result_type
type: select
required: true
options:
- value: text
label:
en_US: text
zh_Hans: 文本
- value: link
label:
en_US: link
zh_Hans: 链接
default: text
label:
en_US: Result type
zh_Hans: 结果类型
human_description:
en_US: used for selecting the result type, text or link
zh_Hans: 用于选择结果类型,使用文本还是链接进行展示
form: form form: form
- name: require_summary - name: require_summary
type: boolean type: boolean

52
api/poetry.lock generated
View File

@ -2076,21 +2076,21 @@ files = [
[[package]] [[package]]
name = "duckduckgo-search" name = "duckduckgo-search"
version = "6.2.1" version = "6.2.6"
description = "Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine." description = "Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine."
optional = false optional = false
python-versions = ">=3.8" python-versions = ">=3.8"
files = [ files = [
{file = "duckduckgo_search-6.2.1-py3-none-any.whl", hash = "sha256:1a03f799b85fdfa08d5e6478624683f373b9dc35e6f145544b9cab72a4f575fa"}, {file = "duckduckgo_search-6.2.6-py3-none-any.whl", hash = "sha256:c8171bcd6ff4d051f78c70ea23bd34c0d8e779d72973829d3a6b40ccc05cd7c2"},
{file = "duckduckgo_search-6.2.1.tar.gz", hash = "sha256:d664ec096193e3fb43bdfae4b0ad9c04e44094b58f41998adcdd20a86ee1ed74"}, {file = "duckduckgo_search-6.2.6.tar.gz", hash = "sha256:96529ecfbd55afa28705b38413003cb3cfc620e55762d33184887545de27dc96"},
] ]
[package.dependencies] [package.dependencies]
click = ">=8.1.7" click = ">=8.1.7"
pyreqwest-impersonate = ">=0.5.0" primp = ">=0.5.5"
[package.extras] [package.extras]
dev = ["mypy (>=1.10.1)", "pytest (>=8.2.2)", "pytest-asyncio (>=0.23.7)", "ruff (>=0.5.2)"] dev = ["mypy (>=1.11.0)", "pytest (>=8.3.1)", "pytest-asyncio (>=0.23.8)", "ruff (>=0.5.5)"]
lxml = ["lxml (>=5.2.2)"] lxml = ["lxml (>=5.2.2)"]
[[package]] [[package]]
@ -5868,6 +5868,26 @@ dev = ["black", "flake8", "flake8-print", "isort", "pre-commit"]
sentry = ["django", "sentry-sdk"] sentry = ["django", "sentry-sdk"]
test = ["coverage", "flake8", "freezegun (==0.3.15)", "mock (>=2.0.0)", "pylint", "pytest", "pytest-timeout"] test = ["coverage", "flake8", "freezegun (==0.3.15)", "mock (>=2.0.0)", "pylint", "pytest", "pytest-timeout"]
[[package]]
name = "primp"
version = "0.5.5"
description = "HTTP client that can impersonate web browsers, mimicking their headers and `TLS/JA3/JA4/HTTP2` fingerprints"
optional = false
python-versions = ">=3.8"
files = [
{file = "primp-0.5.5-cp38-abi3-macosx_10_12_x86_64.whl", hash = "sha256:cff9792e8422424528c23574b5364882d68134ee2743f4a2ae6a765746fb3028"},
{file = "primp-0.5.5-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:78e13fc5d4d90d44a005dbd5dda116981828c803c86cf85816b3bb5363b045c8"},
{file = "primp-0.5.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3714abfda79d3f5c90a5363db58994afbdbacc4b94fe14e9e5f8ab97e7b82577"},
{file = "primp-0.5.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e54765900ee40eceb6bde43676d7e0b2e16ca1f77c0753981fe5e40afc0c2010"},
{file = "primp-0.5.5-cp38-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:66c7eecc5a55225c42cfb99af857df04f994f3dd0d327c016d3af5414c1a2242"},
{file = "primp-0.5.5-cp38-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:df262271cc1a41f4bf80d68396e967a27d7d3d3de355a3d016f953130e7a20be"},
{file = "primp-0.5.5-cp38-abi3-win_amd64.whl", hash = "sha256:8b424118d6bab6f9d4980d0f35d5ccc1213ab9f1042497c6ee11730f2f94a876"},
{file = "primp-0.5.5.tar.gz", hash = "sha256:8623e8a25fd686785296b12175f4173250a08db1de9ee4063282e262b94bf3f2"},
]
[package.extras]
dev = ["pytest (>=8.1.1)"]
[[package]] [[package]]
name = "prompt-toolkit" name = "prompt-toolkit"
version = "3.0.47" version = "3.0.47"
@ -6463,26 +6483,6 @@ files = [
{file = "pyreadline3-3.4.1.tar.gz", hash = "sha256:6f3d1f7b8a31ba32b73917cefc1f28cc660562f39aea8646d30bd6eff21f7bae"}, {file = "pyreadline3-3.4.1.tar.gz", hash = "sha256:6f3d1f7b8a31ba32b73917cefc1f28cc660562f39aea8646d30bd6eff21f7bae"},
] ]
[[package]]
name = "pyreqwest-impersonate"
version = "0.5.3"
description = "HTTP client that can impersonate web browsers, mimicking their headers and `TLS/JA3/JA4/HTTP2` fingerprints"
optional = false
python-versions = ">=3.8"
files = [
{file = "pyreqwest_impersonate-0.5.3-cp38-abi3-macosx_10_12_x86_64.whl", hash = "sha256:f15922496f728769fb9e1b116d5d9d7ba5525d0f2f7a76a41a1daef8b2e0c6c3"},
{file = "pyreqwest_impersonate-0.5.3-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:77533133ae73020e59bc56d776eea3fe3af4ac41d763a89f39c495436da0f4cf"},
{file = "pyreqwest_impersonate-0.5.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:436055fa3eeb3e01e2e8efd42a9f6c4ab62fd643eddc7c66d0e671b71605f273"},
{file = "pyreqwest_impersonate-0.5.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e9d2e981a525fb72c1521f454e5581d2c7a3b1fcf1c97c0acfcb7a923d8cf3e"},
{file = "pyreqwest_impersonate-0.5.3-cp38-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:a6bf986d4a165f6976b3e862111e2a46091883cb55e9e6325150f5aea2644229"},
{file = "pyreqwest_impersonate-0.5.3-cp38-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:b7397f6dad3d5ae158e0b272cb3eafe8382e71775d829b286ae9c21cb5a879ff"},
{file = "pyreqwest_impersonate-0.5.3-cp38-abi3-win_amd64.whl", hash = "sha256:6026e4751b5912aec1e45238c07daf1e2c9126b3b32b33396b72885021e8990c"},
{file = "pyreqwest_impersonate-0.5.3.tar.gz", hash = "sha256:f21c10609958ff5be18df0c329eed42d2b3ba8a339b65dc5f96ab74537231692"},
]
[package.extras]
dev = ["pytest (>=8.1.1)"]
[[package]] [[package]]
name = "pytest" name = "pytest"
version = "8.1.2" version = "8.1.2"
@ -9510,4 +9510,4 @@ cffi = ["cffi (>=1.11)"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = ">=3.10,<3.13" python-versions = ">=3.10,<3.13"
content-hash = "ca0efc924f1f20acdfba068aa571015a10f0e185427dc3b22333be252d706de2" content-hash = "d40cddaa8cd9c7ee7f8bbca06c8dd844facf9b2b618131dd85a41da5e0d47125"

View File

@ -188,7 +188,7 @@ kaleido = "0.2.1"
arxiv = "2.1.0" arxiv = "2.1.0"
matplotlib = "~3.8.2" matplotlib = "~3.8.2"
newspaper3k = "0.2.8" newspaper3k = "0.2.8"
duckduckgo-search = "^6.1.8" duckduckgo-search = "^6.2.6"
jsonpath-ng = "1.6.1" jsonpath-ng = "1.6.1"
numexpr = "~2.9.0" numexpr = "~2.9.0"
opensearch-py = "2.4.0" opensearch-py = "2.4.0"