mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
refactor: replace bare dict with dict[str, Any] in app_config managers (#35087)
This commit is contained in:
parent
3c279edcf2
commit
ac2258c2dc
@ -138,7 +138,9 @@ class DatasetConfigManager:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, tenant_id: str, app_mode: AppMode, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(
|
||||||
|
cls, tenant_id: str, app_mode: AppMode, config: dict[str, Any]
|
||||||
|
) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for dataset feature
|
Validate and set defaults for dataset feature
|
||||||
|
|
||||||
@ -172,7 +174,7 @@ class DatasetConfigManager:
|
|||||||
return config, ["agent_mode", "dataset_configs", "dataset_query_variable"]
|
return config, ["agent_mode", "dataset_configs", "dataset_query_variable"]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def extract_dataset_config_for_legacy_compatibility(cls, tenant_id: str, app_mode: AppMode, config: dict):
|
def extract_dataset_config_for_legacy_compatibility(cls, tenant_id: str, app_mode: AppMode, config: dict[str, Any]):
|
||||||
"""
|
"""
|
||||||
Extract dataset config for legacy compatibility
|
Extract dataset config for legacy compatibility
|
||||||
|
|
||||||
|
|||||||
@ -108,7 +108,7 @@ class ModelConfigManager:
|
|||||||
return dict(config), ["model"]
|
return dict(config), ["model"]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_model_completion_params(cls, cp: dict):
|
def validate_model_completion_params(cls, cp: dict[str, Any]):
|
||||||
# model.completion_params
|
# model.completion_params
|
||||||
if not isinstance(cp, dict):
|
if not isinstance(cp, dict):
|
||||||
raise ValueError("model.completion_params must be of object type")
|
raise ValueError("model.completion_params must be of object type")
|
||||||
|
|||||||
@ -65,7 +65,7 @@ class PromptTemplateConfigManager:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, app_mode: AppMode, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, app_mode: AppMode, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate pre_prompt and set defaults for prompt feature
|
Validate pre_prompt and set defaults for prompt feature
|
||||||
depending on the config['model']
|
depending on the config['model']
|
||||||
@ -130,7 +130,7 @@ class PromptTemplateConfigManager:
|
|||||||
return config, ["prompt_type", "pre_prompt", "chat_prompt_config", "completion_prompt_config"]
|
return config, ["prompt_type", "pre_prompt", "chat_prompt_config", "completion_prompt_config"]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_post_prompt_and_set_defaults(cls, config: dict):
|
def validate_post_prompt_and_set_defaults(cls, config: dict[str, Any]):
|
||||||
"""
|
"""
|
||||||
Validate post_prompt and set defaults for prompt feature
|
Validate post_prompt and set defaults for prompt feature
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
from typing import cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from graphon.variables.input_entities import VariableEntity, VariableEntityType
|
from graphon.variables.input_entities import VariableEntity, VariableEntityType
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ class BasicVariablesConfigManager:
|
|||||||
return variable_entities, external_data_variables
|
return variable_entities, external_data_variables
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, tenant_id: str, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, tenant_id: str, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for user input form
|
Validate and set defaults for user input form
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ class BasicVariablesConfigManager:
|
|||||||
return config, related_config_keys
|
return config, related_config_keys
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_variables_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_variables_and_set_defaults(cls, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for user input form
|
Validate and set defaults for user input form
|
||||||
|
|
||||||
@ -164,7 +164,9 @@ class BasicVariablesConfigManager:
|
|||||||
return config, ["user_input_form"]
|
return config, ["user_input_form"]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_external_data_tools_and_set_defaults(cls, tenant_id: str, config: dict) -> tuple[dict, list[str]]:
|
def validate_external_data_tools_and_set_defaults(
|
||||||
|
cls, tenant_id: str, config: dict[str, Any]
|
||||||
|
) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for external data fetch feature
|
Validate and set defaults for external data fetch feature
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class FileUploadConfigManager:
|
|||||||
return FileUploadConfig.model_validate(file_upload_dict)
|
return FileUploadConfig.model_validate(file_upload_dict)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for file upload feature
|
Validate and set defaults for file upload feature
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
||||||
|
|
||||||
|
|
||||||
@ -13,7 +15,7 @@ class AppConfigModel(BaseModel):
|
|||||||
|
|
||||||
class MoreLikeThisConfigManager:
|
class MoreLikeThisConfigManager:
|
||||||
@classmethod
|
@classmethod
|
||||||
def convert(cls, config: dict) -> bool:
|
def convert(cls, config: dict[str, Any]) -> bool:
|
||||||
"""
|
"""
|
||||||
Convert model config to model config
|
Convert model config to model config
|
||||||
|
|
||||||
@ -23,7 +25,7 @@ class MoreLikeThisConfigManager:
|
|||||||
return AppConfigModel.model_validate(validated_config).more_like_this.enabled
|
return AppConfigModel.model_validate(validated_config).more_like_this.enabled
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
try:
|
try:
|
||||||
return AppConfigModel.model_validate(config).model_dump(), ["more_like_this"]
|
return AppConfigModel.model_validate(config).model_dump(), ["more_like_this"]
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class OpeningStatementConfigManager:
|
class OpeningStatementConfigManager:
|
||||||
@classmethod
|
@classmethod
|
||||||
def convert(cls, config: dict) -> tuple[str, list]:
|
def convert(cls, config: dict[str, Any]) -> tuple[str, list[str]]:
|
||||||
"""
|
"""
|
||||||
Convert model config to model config
|
Convert model config to model config
|
||||||
|
|
||||||
@ -15,7 +18,7 @@ class OpeningStatementConfigManager:
|
|||||||
return opening_statement, suggested_questions_list
|
return opening_statement, suggested_questions_list
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for opening statement feature
|
Validate and set defaults for opening statement feature
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class RetrievalResourceConfigManager:
|
class RetrievalResourceConfigManager:
|
||||||
@classmethod
|
@classmethod
|
||||||
def convert(cls, config: dict) -> bool:
|
def convert(cls, config: dict[str, Any]) -> bool:
|
||||||
show_retrieve_source = False
|
show_retrieve_source = False
|
||||||
retriever_resource_dict = config.get("retriever_resource")
|
retriever_resource_dict = config.get("retriever_resource")
|
||||||
if retriever_resource_dict:
|
if retriever_resource_dict:
|
||||||
@ -10,7 +13,7 @@ class RetrievalResourceConfigManager:
|
|||||||
return show_retrieve_source
|
return show_retrieve_source
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for retriever resource feature
|
Validate and set defaults for retriever resource feature
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class SpeechToTextConfigManager:
|
class SpeechToTextConfigManager:
|
||||||
@classmethod
|
@classmethod
|
||||||
def convert(cls, config: dict) -> bool:
|
def convert(cls, config: dict[str, Any]) -> bool:
|
||||||
"""
|
"""
|
||||||
Convert model config to model config
|
Convert model config to model config
|
||||||
|
|
||||||
@ -15,7 +18,7 @@ class SpeechToTextConfigManager:
|
|||||||
return speech_to_text
|
return speech_to_text
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for speech to text feature
|
Validate and set defaults for speech to text feature
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class SuggestedQuestionsAfterAnswerConfigManager:
|
class SuggestedQuestionsAfterAnswerConfigManager:
|
||||||
@classmethod
|
@classmethod
|
||||||
def convert(cls, config: dict) -> bool:
|
def convert(cls, config: dict[str, Any]) -> bool:
|
||||||
"""
|
"""
|
||||||
Convert model config to model config
|
Convert model config to model config
|
||||||
|
|
||||||
@ -15,7 +18,7 @@ class SuggestedQuestionsAfterAnswerConfigManager:
|
|||||||
return suggested_questions_after_answer
|
return suggested_questions_after_answer
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for suggested questions feature
|
Validate and set defaults for suggested questions feature
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
from core.app.app_config.entities import TextToSpeechEntity
|
from core.app.app_config.entities import TextToSpeechEntity
|
||||||
|
|
||||||
|
|
||||||
class TextToSpeechConfigManager:
|
class TextToSpeechConfigManager:
|
||||||
@classmethod
|
@classmethod
|
||||||
def convert(cls, config: dict):
|
def convert(cls, config: dict[str, Any]):
|
||||||
"""
|
"""
|
||||||
Convert model config to model config
|
Convert model config to model config
|
||||||
|
|
||||||
@ -22,7 +24,7 @@ class TextToSpeechConfigManager:
|
|||||||
return text_to_speech
|
return text_to_speech
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_and_set_defaults(cls, config: dict) -> tuple[dict, list[str]]:
|
def validate_and_set_defaults(cls, config: dict[str, Any]) -> tuple[dict[str, Any], list[str]]:
|
||||||
"""
|
"""
|
||||||
Validate and set defaults for text to speech feature
|
Validate and set defaults for text to speech feature
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user