Skip to content

Commit

Permalink
chore: update duckduckgo tool (#6983)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjlarry authored Aug 6, 2024
1 parent cba9319 commit 312d905
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 65 deletions.
4 changes: 2 additions & 2 deletions api/core/tools/provider/builtin/duckduckgo/tools/ddgo_ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ parameters:
type: select
required: true
options:
- value: gpt-3.5
- value: gpt-4o-mini
label:
en_US: GPT-3.5
en_US: GPT-4o-mini
- value: claude-3-haiku
label:
en_US: Claude 3
Expand Down
19 changes: 6 additions & 13 deletions api/core/tools/provider/builtin/duckduckgo/tools/ddgo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,16 @@ class DuckDuckGoSearchTool(BuiltinTool):
"""
Tool for performing a search using DuckDuckGo search engine.
"""

def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage:
query = tool_parameters.get('query', '')
result_type = tool_parameters.get('result_type', 'text')
max_results = tool_parameters.get('max_results', 10)
def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage | list[ToolInvokeMessage]:
query = tool_parameters.get('query')
max_results = tool_parameters.get('max_results', 5)
require_summary = tool_parameters.get('require_summary', False)
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:
results = "\n".join([res.get("body") for res in response])
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:
prompt = SUMMARY_PROMPT.format(query=query, content=content)
Expand Down
23 changes: 0 additions & 23 deletions api/core/tools/provider/builtin/duckduckgo/tools/ddgo_search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,6 @@ parameters:
label:
en_US: Max results
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
- name: require_summary
type: boolean
Expand Down
52 changes: 26 additions & 26 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ kaleido = "0.2.1"
arxiv = "2.1.0"
matplotlib = "~3.8.2"
newspaper3k = "0.2.8"
duckduckgo-search = "^6.1.8"
duckduckgo-search = "^6.2.6"
jsonpath-ng = "1.6.1"
numexpr = "~2.9.0"
opensearch-py = "2.4.0"
Expand Down

0 comments on commit 312d905

Please sign in to comment.