From 2cb640de15b38d6023b6fec7d8b25a2f3bf531f7 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Fri, 15 Nov 2024 19:53:50 +0800 Subject: [PATCH] refactor: load tools cache --- api/controllers/files/plugin_files.py | 18 ++++++++++++++++++ api/core/tools/builtin_tool/provider.py | 19 ++++++++++--------- api/core/tools/plugin_tool/tool.py | 1 - 3 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 api/controllers/files/plugin_files.py diff --git a/api/controllers/files/plugin_files.py b/api/controllers/files/plugin_files.py new file mode 100644 index 0000000000..bf1d7a03c6 --- /dev/null +++ b/api/controllers/files/plugin_files.py @@ -0,0 +1,18 @@ +from flask_restful import Resource, reqparse + +from controllers.files import api + + +class PluginFilePreviewApi(Resource): + def get(self, file_id: str, file_type: str): + parser = reqparse.RequestParser() + + parser.add_argument("timestamp", type=str, required=True, location="args") + parser.add_argument("nonce", type=str, required=True, location="args") + parser.add_argument("sign", type=str, required=True, location="args") + parser.add_argument("as_attachment", type=bool, required=False, default=False, location="args") + + args = parser.parse_args() + + +api.add_resource(PluginFilePreviewApi, "/files///plugin-file-preview") diff --git a/api/core/tools/builtin_tool/provider.py b/api/core/tools/builtin_tool/provider.py index 18ad385e49..15635b4f25 100644 --- a/api/core/tools/builtin_tool/provider.py +++ b/api/core/tools/builtin_tool/provider.py @@ -45,15 +45,9 @@ class BuiltinToolProviderController(ToolProviderController): ), ) - def _get_builtin_tools(self) -> list[BuiltinTool]: - """ - returns a list of tools that the provider can provide - - :return: list of tools - """ - if self.tools: - return self.tools + self._load_tools() + def _load_tools(self): provider = self.entity.identity.name tool_path = path.join(path.dirname(path.realpath(__file__)), "providers", provider, "tools") # get all the yaml files in the tool path @@ -86,7 +80,14 @@ class BuiltinToolProviderController(ToolProviderController): ) self.tools = tools - return tools + + def _get_builtin_tools(self) -> list[BuiltinTool]: + """ + returns a list of tools that the provider can provide + + :return: list of tools + """ + return self.tools def get_credentials_schema(self) -> list[ProviderConfig]: """ diff --git a/api/core/tools/plugin_tool/tool.py b/api/core/tools/plugin_tool/tool.py index 1ac8c75202..4e5c65ab94 100644 --- a/api/core/tools/plugin_tool/tool.py +++ b/api/core/tools/plugin_tool/tool.py @@ -18,7 +18,6 @@ class PluginTool(Tool): self.tenant_id = tenant_id self.runtime_parameters = None - @property def tool_provider_type(self) -> ToolProviderType: return ToolProviderType.PLUGIN