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: replace bare dict with dict[str, Any] in model provider service and core modules (#35122)

wdeveloper16bd7a9b5fcfd6
diff --git a/api/core/agent/output_parser/cot_output_parser.py b/api/core/agent/output_parser/cot_output_parser.py
index 46c1f1230d0..8cccd2be6dd 100644
--- a/api/core/agent/output_parser/cot_output_parser.py
+++ b/api/core/agent/output_parser/cot_output_parser.py
@@ -1,7 +1,7 @@
import json
import re
from collections.abc import Generator
-from typing import Union
+from typing import Any, Union
from graphon.model_runtime.entities.llm_entities import LLMResultChunk
@@ -11,7 +11,7 @@ from core.agent.entities import AgentScratchpadUnit
class CotAgentOutputParser:
@classmethod
def handle_react_stream_output(
- cls, llm_response: Generator[LLMResultChunk, None, None], usage_dict: dict
+ cls, llm_response: Generator[LLMResultChunk, None, None], usage_dict: dict[str, Any]
) -> Generator[Union[str, AgentScratchpadUnit.Action], None, None]:
def parse_action(action) -> Union[str, AgentScratchpadUnit.Action]:
action_name = None
diff --git a/api/core/schemas/resolver.py b/api/core/schemas/resolver.py
index 6e26664ac25..e267c1abd9a 100644
--- a/api/core/schemas/resolver.py
+++ b/api/core/schemas/resolver.py
@@ -254,7 +254,7 @@ def resolve_dify_schema_refs(
return resolver.resolve(schema)
-def _remove_metadata_fields(schema: dict) -> dict:
+def _remove_metadata_fields(schema: dict[str, Any]) -> dict[str, Any]:
"""
Remove metadata fields from schema that shouldn't be included in resolved output
diff --git a/api/services/model_provider_service.py b/api/services/model_provider_service.py
index 3f37c9b176d..bf208c9bc73 100644
--- a/api/services/model_provider_service.py
+++ b/api/services/model_provider_service.py
@@ -1,4 +1,5 @@
import logging
+from typing import Any
from graphon.model_runtime.entities.model_entities import ModelType, ParameterRule
@@ -168,7 +169,9 @@ class ModelProviderService:
model_name=model,
)
- def get_provider_credential(self, tenant_id: str, provider: str, credential_id: str | None = None) -> dict | None:
+ def get_provider_credential(
+ self, tenant_id: str, provider: str, credential_id: str | None = None
+ ) -> dict[str, Any] | None:
"""
get provider credentials.
@@ -180,7 +183,7 @@ class ModelProviderService:
provider_configuration = self._get_provider_configuration(tenant_id, provider)
return provider_configuration.get_provider_credential(credential_id=credential_id)
- def validate_provider_credentials(self, tenant_id: str, provider: str, credentials: dict):
+ def validate_provider_credentials(self, tenant_id: str, provider: str, credentials: dict[str, Any]):
"""
validate provider credentials before saving.
@@ -192,7 +195,7 @@ class ModelProviderService:
provider_configuration.validate_provider_credentials(credentials)
def create_provider_credential(
- self, tenant_id: str, provider: str, credentials: dict, credential_name: str | None
+ self, tenant_id: str, provider: str, credentials: dict[str, Any], credential_name: str | None
) -> None:
"""
Create and save new provider credentials.
@@ -210,7 +213,7 @@ class ModelProviderService:
self,
tenant_id: str,
provider: str,
- credentials: dict,
+ credentials: dict[str, Any],
credential_id: str,
credential_name: str | None,
) -> None:
@@ -254,7 +257,7 @@ class ModelProviderService:
def get_model_credential(
self, tenant_id: str, provider: str, model_type: str, model: str, credential_id: str | None
- ) -> dict | None:
+ ) -> dict[str, Any] | None:
"""
Retrieve model-specific credentials.
@@ -270,7 +273,9 @@ class ModelProviderService:
model_type=ModelType.value_of(model_type), model=model, credential_id=credential_id
)
- def validate_model_credentials(self, tenant_id: str, provider: str, model_type: str, model: str, credentials: dict):
+ def validate_model_credentials(
+ self, tenant_id: str, provider: str, model_type: str, model: str, credentials: dict[str, Any]
+ ):
"""
validate model credentials.
@@ -287,7 +292,13 @@ class ModelProviderService:
)
def create_model_credential(
- self, tenant_id: str, provider: str, model_type: str, model: str, credentials: dict, credential_name: str | None
+ self,
+ tenant_id: str,
+ provider: str,
+ model_type: str,
+ model: str,
+ credentials: dict[str, Any],
+ credential_name: str | None,
) -> None:
"""
create and save model credentials.
@@ -314,7 +325,7 @@ class ModelProviderService:
provider: str,
model_type: str,
model: str,
- credentials: dict,
+ credentials: dict[str, Any],
credential_id: str,
credential_name: str | None,
) -> None: