mirror of
https://github.com/langgenius/dify.git
synced 2026-05-01 07:58:02 +08:00
remove bare list, dict, Sequence, None, Any (#25058)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
@ -35,7 +35,7 @@ class Callback(ABC):
|
||||
stop: Optional[Sequence[str]] = None,
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
Before invoke callback
|
||||
|
||||
@ -94,7 +94,7 @@ class Callback(ABC):
|
||||
stop: Optional[Sequence[str]] = None,
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
After invoke callback
|
||||
|
||||
@ -124,7 +124,7 @@ class Callback(ABC):
|
||||
stop: Optional[Sequence[str]] = None,
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
Invoke error callback
|
||||
|
||||
@ -141,7 +141,7 @@ class Callback(ABC):
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def print_text(self, text: str, color: Optional[str] = None, end: str = "") -> None:
|
||||
def print_text(self, text: str, color: Optional[str] = None, end: str = ""):
|
||||
"""Print text with highlighting and no end characters."""
|
||||
text_to_print = self._get_colored_text(text, color) if color else text
|
||||
print(text_to_print, end=end)
|
||||
|
||||
@ -24,7 +24,7 @@ class LoggingCallback(Callback):
|
||||
stop: Optional[Sequence[str]] = None,
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
Before invoke callback
|
||||
|
||||
@ -110,7 +110,7 @@ class LoggingCallback(Callback):
|
||||
stop: Optional[Sequence[str]] = None,
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
After invoke callback
|
||||
|
||||
@ -151,7 +151,7 @@ class LoggingCallback(Callback):
|
||||
stop: Optional[Sequence[str]] = None,
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
Invoke error callback
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ class InvokeError(ValueError):
|
||||
|
||||
description: Optional[str] = None
|
||||
|
||||
def __init__(self, description: Optional[str] = None) -> None:
|
||||
def __init__(self, description: Optional[str] = None):
|
||||
self.description = description
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@ -239,7 +239,7 @@ class AIModel(BaseModel):
|
||||
"""
|
||||
return None
|
||||
|
||||
def _get_default_parameter_rule_variable_map(self, name: DefaultParameterName) -> dict:
|
||||
def _get_default_parameter_rule_variable_map(self, name: DefaultParameterName):
|
||||
"""
|
||||
Get default parameter rule for given name
|
||||
|
||||
|
||||
@ -408,7 +408,7 @@ class LargeLanguageModel(AIModel):
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
callbacks: Optional[list[Callback]] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
Trigger before invoke callbacks
|
||||
|
||||
@ -456,7 +456,7 @@ class LargeLanguageModel(AIModel):
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
callbacks: Optional[list[Callback]] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
Trigger new chunk callbacks
|
||||
|
||||
@ -503,7 +503,7 @@ class LargeLanguageModel(AIModel):
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
callbacks: Optional[list[Callback]] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
Trigger after invoke callbacks
|
||||
|
||||
@ -553,7 +553,7 @@ class LargeLanguageModel(AIModel):
|
||||
stream: bool = True,
|
||||
user: Optional[str] = None,
|
||||
callbacks: Optional[list[Callback]] = None,
|
||||
) -> None:
|
||||
):
|
||||
"""
|
||||
Trigger invoke error callbacks
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ class GPT2Tokenizer:
|
||||
return GPT2Tokenizer._get_num_tokens_by_gpt2(text)
|
||||
|
||||
@staticmethod
|
||||
def get_encoder() -> Any:
|
||||
def get_encoder():
|
||||
global _tokenizer, _lock
|
||||
if _tokenizer is not None:
|
||||
return _tokenizer
|
||||
|
||||
@ -56,7 +56,7 @@ class TTSModel(AIModel):
|
||||
except Exception as e:
|
||||
raise self._transform_invoke_error(e)
|
||||
|
||||
def get_tts_model_voices(self, model: str, credentials: dict, language: Optional[str] = None) -> list[dict]:
|
||||
def get_tts_model_voices(self, model: str, credentials: dict, language: Optional[str] = None):
|
||||
"""
|
||||
Retrieves the list of voices supported by a given text-to-speech (TTS) model.
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ class ModelProviderExtension(BaseModel):
|
||||
class ModelProviderFactory:
|
||||
provider_position_map: dict[str, int]
|
||||
|
||||
def __init__(self, tenant_id: str) -> None:
|
||||
def __init__(self, tenant_id: str):
|
||||
self.provider_position_map = {}
|
||||
|
||||
self.tenant_id = tenant_id
|
||||
@ -132,7 +132,7 @@ class ModelProviderFactory:
|
||||
|
||||
return plugin_model_provider_entity
|
||||
|
||||
def provider_credentials_validate(self, *, provider: str, credentials: dict) -> dict:
|
||||
def provider_credentials_validate(self, *, provider: str, credentials: dict):
|
||||
"""
|
||||
Validate provider credentials
|
||||
|
||||
@ -163,9 +163,7 @@ class ModelProviderFactory:
|
||||
|
||||
return filtered_credentials
|
||||
|
||||
def model_credentials_validate(
|
||||
self, *, provider: str, model_type: ModelType, model: str, credentials: dict
|
||||
) -> dict:
|
||||
def model_credentials_validate(self, *, provider: str, model_type: ModelType, model: str, credentials: dict):
|
||||
"""
|
||||
Validate model credentials
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ from core.model_runtime.entities.provider_entities import CredentialFormSchema,
|
||||
class CommonValidator:
|
||||
def _validate_and_filter_credential_form_schemas(
|
||||
self, credential_form_schemas: list[CredentialFormSchema], credentials: dict
|
||||
) -> dict:
|
||||
):
|
||||
need_validate_credential_form_schema_map = {}
|
||||
for credential_form_schema in credential_form_schemas:
|
||||
if not credential_form_schema.show_on:
|
||||
|
||||
@ -8,7 +8,7 @@ class ModelCredentialSchemaValidator(CommonValidator):
|
||||
self.model_type = model_type
|
||||
self.model_credential_schema = model_credential_schema
|
||||
|
||||
def validate_and_filter(self, credentials: dict) -> dict:
|
||||
def validate_and_filter(self, credentials: dict):
|
||||
"""
|
||||
Validate model credentials
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ class ProviderCredentialSchemaValidator(CommonValidator):
|
||||
def __init__(self, provider_credential_schema: ProviderCredentialSchema):
|
||||
self.provider_credential_schema = provider_credential_schema
|
||||
|
||||
def validate_and_filter(self, credentials: dict) -> dict:
|
||||
def validate_and_filter(self, credentials: dict):
|
||||
"""
|
||||
Validate provider credentials
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ from pydantic_core import Url
|
||||
from pydantic_extra_types.color import Color
|
||||
|
||||
|
||||
def _model_dump(model: BaseModel, mode: Literal["json", "python"] = "json", **kwargs: Any) -> Any:
|
||||
def _model_dump(model: BaseModel, mode: Literal["json", "python"] = "json", **kwargs: Any):
|
||||
return model.model_dump(mode=mode, **kwargs)
|
||||
|
||||
|
||||
@ -100,7 +100,7 @@ def jsonable_encoder(
|
||||
exclude_none: bool = False,
|
||||
custom_encoder: Optional[dict[Any, Callable[[Any], Any]]] = None,
|
||||
sqlalchemy_safe: bool = True,
|
||||
) -> Any:
|
||||
):
|
||||
custom_encoder = custom_encoder or {}
|
||||
if custom_encoder:
|
||||
if type(obj) in custom_encoder:
|
||||
|
||||
Reference in New Issue
Block a user