Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor: split changes for api/services/tools/api_tools_manage_servi… (#29899)

Asuka Minatofb5edd0bf651
diff --git a/api/.ruff.toml b/api/.ruff.toml
index 7206f7fa0fa..8db0cbcb21e 100644
--- a/api/.ruff.toml
+++ b/api/.ruff.toml
@@ -1,4 +1,8 @@
-exclude = ["migrations/*"]
+exclude = [
+ "migrations/*",
+ ".git",
+ ".git/**",
+]
line-length = 120
[format]
diff --git a/api/core/tools/utils/parser.py b/api/core/tools/utils/parser.py
index 34861821923..584975de050 100644
--- a/api/core/tools/utils/parser.py
+++ b/api/core/tools/utils/parser.py
@@ -378,7 +378,7 @@ class ApiBasedToolSchemaParser:
@staticmethod
def auto_parse_to_tool_bundle(
content: str, extra_info: dict | None = None, warning: dict | None = None
- ) -> tuple[list[ApiToolBundle], str]:
+ ) -> tuple[list[ApiToolBundle], ApiProviderSchemaType]:
"""
auto parse to tool bundle
diff --git a/api/services/tools/api_tools_manage_service.py b/api/services/tools/api_tools_manage_service.py
index 250d29f335a..c32157919b3 100644
--- a/api/services/tools/api_tools_manage_service.py
+++ b/api/services/tools/api_tools_manage_service.py
@@ -85,7 +85,9 @@ class ApiToolManageService:
raise ValueError(f"invalid schema: {str(e)}")
@staticmethod
- def convert_schema_to_tool_bundles(schema: str, extra_info: dict | None = None) -> tuple[list[ApiToolBundle], str]:
+ def convert_schema_to_tool_bundles(
+ schema: str, extra_info: dict | None = None
+ ) -> tuple[list[ApiToolBundle], ApiProviderSchemaType]:
"""
convert schema to tool bundles
@@ -103,7 +105,7 @@ class ApiToolManageService:
provider_name: str,
icon: dict,
credentials: dict,
- schema_type: str,
+ schema_type: ApiProviderSchemaType,
schema: str,
privacy_policy: str,
custom_disclaimer: str,
@@ -112,9 +114,6 @@ class ApiToolManageService:
"""
create api tool provider
"""
- if schema_type not in [member.value for member in ApiProviderSchemaType]:
- raise ValueError(f"invalid schema type {schema}")
-
provider_name = provider_name.strip()
# check if the provider exists
@@ -241,18 +240,15 @@ class ApiToolManageService:
original_provider: str,
icon: dict,
credentials: dict,
- schema_type: str,
+ _schema_type: ApiProviderSchemaType,
schema: str,
- privacy_policy: str,
+ privacy_policy: str | None,
custom_disclaimer: str,
labels: list[str],
):
"""
update api tool provider
"""
- if schema_type not in [member.value for member in ApiProviderSchemaType]:
- raise ValueError(f"invalid schema type {schema}")
-
provider_name = provider_name.strip()
# check if the provider exists
@@ -277,7 +273,7 @@ class ApiToolManageService:
provider.icon = json.dumps(icon)
provider.schema = schema
provider.description = extra_info.get("description", "")
- provider.schema_type_str = ApiProviderSchemaType.OPENAPI
+ provider.schema_type_str = schema_type
provider.tools_str = json.dumps(jsonable_encoder(tool_bundles))
provider.privacy_policy = privacy_policy
provider.custom_disclaimer = custom_disclaimer
@@ -356,7 +352,7 @@ class ApiToolManageService:
tool_name: str,
credentials: dict,
parameters: dict,
- schema_type: str,
+ schema_type: ApiProviderSchemaType,
schema: str,
):
"""