diff --git a/api/core/tools/provider/builtin/arxiv/_assets/icon.svg b/api/core/tools/provider/builtin/arxiv/_assets/icon.svg new file mode 100644 index 0000000000..0e60f63573 --- /dev/null +++ b/api/core/tools/provider/builtin/arxiv/_assets/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/api/core/tools/provider/builtin/arxiv/arxiv.py b/api/core/tools/provider/builtin/arxiv/arxiv.py new file mode 100644 index 0000000000..998128522e --- /dev/null +++ b/api/core/tools/provider/builtin/arxiv/arxiv.py @@ -0,0 +1,20 @@ +from core.tools.errors import ToolProviderCredentialValidationError +from core.tools.provider.builtin.arxiv.tools.arxiv_search import ArxivSearchTool +from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController + + +class ArxivProvider(BuiltinToolProviderController): + def _validate_credentials(self, credentials: dict) -> None: + try: + ArxivSearchTool().fork_tool_runtime( + meta={ + "credentials": credentials, + } + ).invoke( + user_id='', + tool_parameters={ + "query": "John Doe", + }, + ) + except Exception as e: + raise ToolProviderCredentialValidationError(str(e)) \ No newline at end of file diff --git a/api/core/tools/provider/builtin/arxiv/arxiv.yaml b/api/core/tools/provider/builtin/arxiv/arxiv.yaml new file mode 100644 index 0000000000..78c5c161af --- /dev/null +++ b/api/core/tools/provider/builtin/arxiv/arxiv.yaml @@ -0,0 +1,10 @@ +identity: + author: Yash Parmar + name: arxiv + label: + en_US: ArXiv + zh_Hans: ArXiv + description: + en_US: Access to a vast repository of scientific papers and articles in various fields of research. + zh_Hans: 访问各个研究领域大量科学论文和文章的存储库。 + icon: icon.svg diff --git a/api/core/tools/provider/builtin/arxiv/tools/arxiv_search.py b/api/core/tools/provider/builtin/arxiv/tools/arxiv_search.py new file mode 100644 index 0000000000..033d942f4d --- /dev/null +++ b/api/core/tools/provider/builtin/arxiv/tools/arxiv_search.py @@ -0,0 +1,37 @@ +from typing import Any + +from langchain.utilities import ArxivAPIWrapper +from pydantic import BaseModel, Field + +from core.tools.entities.tool_entities import ToolInvokeMessage +from core.tools.tool.builtin_tool import BuiltinTool + + +class ArxivSearchInput(BaseModel): + query: str = Field(..., description="Search query.") + +class ArxivSearchTool(BuiltinTool): + """ + A tool for searching articles on Arxiv. + """ + def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage | list[ToolInvokeMessage]: + """ + Invokes the Arxiv search tool with the given user ID and tool parameters. + + Args: + user_id (str): The ID of the user invoking the tool. + tool_parameters (dict[str, Any]): The parameters for the tool, including the 'query' parameter. + + Returns: + ToolInvokeMessage | list[ToolInvokeMessage]: The result of the tool invocation, which can be a single message or a list of messages. + """ + query = tool_parameters.get('query', '') + + if not query: + return self.create_text_message('Please input query') + + arxiv = ArxivAPIWrapper() + + response = arxiv.run(query) + + return self.create_text_message(self.summary(user_id=user_id, content=response)) diff --git a/api/core/tools/provider/builtin/arxiv/tools/arxiv_search.yaml b/api/core/tools/provider/builtin/arxiv/tools/arxiv_search.yaml new file mode 100644 index 0000000000..7439a48658 --- /dev/null +++ b/api/core/tools/provider/builtin/arxiv/tools/arxiv_search.yaml @@ -0,0 +1,23 @@ +identity: + name: arxiv_search + author: Yash Parmar + label: + en_US: Arxiv Search + zh_Hans: Arxiv 搜索 +description: + human: + en_US: A tool for searching scientific papers and articles from the Arxiv repository. Input can be an Arxiv ID or an author's name. + zh_Hans: 一个用于从Arxiv存储库搜索科学论文和文章的工具。 输入可以是Arxiv ID或作者姓名。 + llm: A tool for searching scientific papers and articles from the Arxiv repository. Input can be an Arxiv ID or an author's name. +parameters: + - name: query + type: string + required: true + label: + en_US: Query string + zh_Hans: 查询字符串 + human_description: + en_US: The Arxiv ID or author's name used for searching. + zh_Hans: 用于搜索的Arxiv ID或作者姓名。 + llm_description: The Arxiv ID or author's name used for searching. + form: llm diff --git a/api/requirements.txt b/api/requirements.txt index 5881c99903..fbadcdbf04 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -66,4 +66,5 @@ yfinance~=0.2.35 pydub~=0.25.1 gmpy2~=2.1.5 numexpr~=2.9.0 -duckduckgo-search==4.4.3 \ No newline at end of file +duckduckgo-search==4.4.3 +arxiv==2.1.0 \ No newline at end of file