diff --git a/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py b/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py index 0796cd2392a68b..ef2990bfe45a56 100644 --- a/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py +++ b/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.py @@ -7,7 +7,6 @@ WIKIPEDIA_MAX_QUERY_LENGTH = 300 - class WikipediaAPIWrapper: """Wrapper around WikipediaAPI. @@ -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 @@ -57,7 +53,6 @@ def _fetch_page(self, page: str) -> Optional[str]: ): return None - class WikipediaQueryRun: """Tool that searches the Wikipedia API.""" @@ -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)) + \ No newline at end of file diff --git a/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.yaml b/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.yaml index 98d002df1c0daa..376163841e3151 100644 --- a/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.yaml +++ b/api/core/tools/provider/builtin/wikipedia/tools/wikipedia_search.yaml @@ -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: 中文