Skip to content

Commit

Permalink
Revert "feat: allow non-english wikipedias to be searched (#5371)"
Browse files Browse the repository at this point in the history
This reverts commit 0e3113b.
  • Loading branch information
ZhouhaoJiang committed Jun 21, 2024
1 parent bde87c3 commit 995bfbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 97 deletions.
36 changes: 13 additions & 23 deletions api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

WIKIPEDIA_MAX_QUERY_LENGTH = 300


class WikipediaAPIWrapper:
"""Wrapper around WikipediaAPI.
Expand All @@ -26,10 +25,7 @@ class WikipediaAPIWrapper:
def __init__(self, doc_content_chars_max: int = 4000):
self.doc_content_chars_max = doc_content_chars_max

def run(self, query: str, lang: str = "") -> str:
if lang in wikipedia.languages().keys():
self.lang = lang

def run(self, query: str) -> str:
wikipedia.set_lang(self.lang)
wiki_client = wikipedia

Expand Down Expand Up @@ -57,7 +53,6 @@ def _fetch_page(self, page: str) -> Optional[str]:
):
return None


class WikipediaQueryRun:
"""Tool that searches the Wikipedia API."""

Expand All @@ -76,31 +71,26 @@ def __init__(self, api_wrapper: WikipediaAPIWrapper):
def _run(
self,
query: str,
lang: str = "",
) -> str:
"""Use the Wikipedia tool."""
return self.api_wrapper.run(query, lang)


return self.api_wrapper.run(query)
class WikiPediaSearchTool(BuiltinTool):

def _invoke(
self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
def _invoke(self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
invoke tools
invoke tools
"""
query = tool_parameters.get("query", "")
lang = tool_parameters.get("language", "")
query = tool_parameters.get('query', '')
if not query:
return self.create_text_message("Please input query")

return self.create_text_message('Please input query')
tool = WikipediaQueryRun(
api_wrapper=WikipediaAPIWrapper(doc_content_chars_max=4000),
)

result = tool._run(query, lang)
result = tool._run(query)

return self.create_text_message(self.summary(user_id=user_id, content=result))
return self.create_text_message(self.summary(user_id=user_id,content=result))

Original file line number Diff line number Diff line change
Expand Up @@ -24,78 +24,5 @@ parameters:
en_US: key words for searching
zh_Hans: 查询关键词
pt_BR: key words for searching
llm_description: key words for searching, this should be in the language of "language" parameter
llm_description: key words for searching
form: llm
- name: language
type: string
required: true
label:
en_US: Language
zh_Hans: 语言
human_description:
en_US: The language of the Wikipedia to be searched
zh_Hans: 要搜索的维基百科语言
llm_description: >-
language of the wikipedia to be searched,
only "de" for German,
"en" for English,
"fr" for French,
"hi" for Hindi,
"ja" for Japanese,
"ko" for Korean,
"pl" for Polish,
"pt" for Portuguese,
"ro" for Romanian,
"uk" for Ukrainian,
"vi" for Vietnamese,
and "zh" for Chinese are supported
form: llm
options:
- value: de
label:
en_US: German
zh_Hans: 德语
- value: en
label:
en_US: English
zh_Hans: 英语
- value: fr
label:
en_US: French
zh_Hans: 法语
- value: hi
label:
en_US: Hindi
zh_Hans: 印地语
- value: ja
label:
en_US: Japanese
zh_Hans: 日语
- value: ko
label:
en_US: Korean
zh_Hans: 韩语
- value: pl
label:
en_US: Polish
zh_Hans: 波兰语
- value: pt
label:
en_US: Portuguese
zh_Hans: 葡萄牙语
- value: ro
label:
en_US: Romanian
zh_Hans: 罗马尼亚语
- value: uk
label:
en_US: Ukrainian
zh_Hans: 乌克兰语
- value: vi
label:
en_US: Vietnamese
zh_Hans: 越南语
- value: zh
label:
en_US: Chinese
zh_Hans: 中文

0 comments on commit 995bfbf

Please sign in to comment.