mirror of
https://github.com/langgenius/dify.git
synced 2026-06-26 23:01:11 +08:00
refactor: clean unnecessary | None annotations in entities (#35557)
Remove unnecessary '| None' type annotations where the default value already guarantees a non-None type. This is the second batch of cleanups following PR #36824. Patterns changed: - 'bool | None = False' -> 'bool = False' - 'bool | None = Field(default=False)' -> 'bool = Field(default=False)' - 'int | None = Field(default=0)' -> 'int = Field(default=0)' - 'float | None = Field(default=0.0)' -> 'float = Field(default=0.0)' - 'str | None = ""' -> 'str = ""' - 'str | None = Field(default="")' -> 'str = Field(default="")' - 'list[...] | None = Field(default_factory=list)' -> 'list[...] = Field(default_factory=list)'
This commit is contained in:
parent
c71f03f590
commit
422ebf59ea
@ -102,7 +102,7 @@ class DatasetUpdatePayload(BaseModel):
|
||||
external_knowledge_id: str | None = None
|
||||
external_knowledge_api_id: str | None = None
|
||||
icon_info: dict[str, Any] | None = Field(default=None)
|
||||
is_multimodal: bool | None = False
|
||||
is_multimodal: bool = False
|
||||
|
||||
@field_validator("indexing_technique")
|
||||
@classmethod
|
||||
|
||||
@ -77,7 +77,7 @@ class CreateSnippetPayload(BaseModel):
|
||||
type: Literal["node", "group"] = "node"
|
||||
icon_info: IconInfo | None = None
|
||||
graph: dict[str, Any] | None = Field(default=None)
|
||||
input_fields: list[InputFieldDefinition] | None = Field(default_factory=list)
|
||||
input_fields: list[InputFieldDefinition] = Field(default_factory=list)
|
||||
|
||||
|
||||
class UpdateSnippetPayload(BaseModel):
|
||||
|
||||
@ -138,7 +138,7 @@ class WorkflowToolBasePayload(BaseModel):
|
||||
description: str
|
||||
icon: dict[str, Any]
|
||||
parameters: list[WorkflowToolParameterConfiguration] = Field(default_factory=list)
|
||||
privacy_policy: str | None = ""
|
||||
privacy_policy: str = ""
|
||||
labels: list[str] | None = None
|
||||
|
||||
@field_validator("name")
|
||||
|
||||
@ -34,7 +34,7 @@ def print_text(text: str, color: str | None = None, end: str = "", file: TextIO
|
||||
class DifyAgentCallbackHandler(BaseModel):
|
||||
"""Callback Handler that prints to std out."""
|
||||
|
||||
color: str | None = ""
|
||||
color: str = ""
|
||||
current_loop: int = 1
|
||||
|
||||
def __init__(self, color: str | None = None):
|
||||
|
||||
@ -49,8 +49,8 @@ class DatasourceProviderApiEntity(BaseModel):
|
||||
original_credentials: dict[str, Any] | None = None
|
||||
is_team_authorization: bool = False
|
||||
allow_delete: bool = True
|
||||
plugin_id: str | None = Field(default="", description="The plugin id of the datasource")
|
||||
plugin_unique_identifier: str | None = Field(default="", description="The unique identifier of the datasource")
|
||||
plugin_id: str = Field(default="", description="The plugin id of the datasource")
|
||||
plugin_unique_identifier: str = Field(default="", description="The unique identifier of the datasource")
|
||||
datasources: list[DatasourceApiEntity] = Field(default_factory=list)
|
||||
labels: list[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
@ -318,8 +318,8 @@ class WebSiteInfo(BaseModel):
|
||||
|
||||
status: str | None = Field(..., description="crawl job status")
|
||||
web_info_list: list[WebSiteInfoDetail] | None = []
|
||||
total: int | None = Field(default=0, description="The total number of websites")
|
||||
completed: int | None = Field(default=0, description="The number of completed websites")
|
||||
total: int = Field(default=0, description="The total number of websites")
|
||||
completed: int = Field(default=0, description="The number of completed websites")
|
||||
|
||||
|
||||
class WebsiteCrawlMessage(BaseModel):
|
||||
|
||||
@ -113,7 +113,7 @@ class CustomModelConfiguration(BaseModel):
|
||||
current_credential_id: str | None = None
|
||||
current_credential_name: str | None = None
|
||||
available_model_credentials: list[CredentialConfiguration] = []
|
||||
unadded_to_model_list: bool | None = False
|
||||
unadded_to_model_list: bool = False
|
||||
|
||||
# pydantic configs
|
||||
model_config = ConfigDict(protected_namespaces=())
|
||||
@ -209,7 +209,7 @@ class ProviderConfig(BasicProviderConfig):
|
||||
required: bool = False
|
||||
default: Union[int, str, float, bool] | None = None
|
||||
options: list[Option] | None = None
|
||||
multiple: bool | None = False
|
||||
multiple: bool = False
|
||||
label: I18nObject | None = None
|
||||
help: I18nObject | None = None
|
||||
url: str | None = None
|
||||
|
||||
@ -24,7 +24,7 @@ class EndpointProviderDeclaration(BaseModel):
|
||||
"""
|
||||
|
||||
settings: list[ProviderConfig] = Field(default_factory=list)
|
||||
endpoints: list[EndpointDeclaration] | None = Field(default_factory=list[EndpointDeclaration])
|
||||
endpoints: list[EndpointDeclaration] = Field(default_factory=list[EndpointDeclaration])
|
||||
|
||||
|
||||
class EndpointEntity(BasePluginEntity):
|
||||
|
||||
@ -28,25 +28,25 @@ class PluginResourceRequirements(BaseModel):
|
||||
|
||||
class Permission(BaseModel):
|
||||
class Tool(BaseModel):
|
||||
enabled: bool | None = Field(default=False)
|
||||
enabled: bool = Field(default=False)
|
||||
|
||||
class Model(BaseModel):
|
||||
enabled: bool | None = Field(default=False)
|
||||
llm: bool | None = Field(default=False)
|
||||
text_embedding: bool | None = Field(default=False)
|
||||
rerank: bool | None = Field(default=False)
|
||||
tts: bool | None = Field(default=False)
|
||||
speech2text: bool | None = Field(default=False)
|
||||
moderation: bool | None = Field(default=False)
|
||||
enabled: bool = Field(default=False)
|
||||
llm: bool = Field(default=False)
|
||||
text_embedding: bool = Field(default=False)
|
||||
rerank: bool = Field(default=False)
|
||||
tts: bool = Field(default=False)
|
||||
speech2text: bool = Field(default=False)
|
||||
moderation: bool = Field(default=False)
|
||||
|
||||
class Node(BaseModel):
|
||||
enabled: bool | None = Field(default=False)
|
||||
enabled: bool = Field(default=False)
|
||||
|
||||
class Endpoint(BaseModel):
|
||||
enabled: bool | None = Field(default=False)
|
||||
enabled: bool = Field(default=False)
|
||||
|
||||
class Storage(BaseModel):
|
||||
enabled: bool | None = Field(default=False)
|
||||
enabled: bool = Field(default=False)
|
||||
size: int = Field(ge=1024, le=1073741824, default=1048576)
|
||||
|
||||
tool: Tool | None = Field(default=None)
|
||||
@ -69,11 +69,11 @@ class PluginCategory(StrEnum):
|
||||
|
||||
class PluginDeclaration(BaseModel):
|
||||
class Plugins(BaseModel):
|
||||
tools: list[str] | None = Field(default_factory=list[str])
|
||||
models: list[str] | None = Field(default_factory=list[str])
|
||||
endpoints: list[str] | None = Field(default_factory=list[str])
|
||||
datasources: list[str] | None = Field(default_factory=list[str])
|
||||
triggers: list[str] | None = Field(default_factory=list[str])
|
||||
tools: list[str] = Field(default_factory=list[str])
|
||||
models: list[str] = Field(default_factory=list[str])
|
||||
endpoints: list[str] = Field(default_factory=list[str])
|
||||
datasources: list[str] = Field(default_factory=list[str])
|
||||
triggers: list[str] = Field(default_factory=list[str])
|
||||
|
||||
class Meta(BaseModel):
|
||||
minimum_dify_version: str | None = Field(default=None)
|
||||
|
||||
@ -71,9 +71,9 @@ class RequestInvokeLLM(BaseRequestInvokeModel):
|
||||
mode: str
|
||||
completion_params: dict[str, Any] = Field(default_factory=dict)
|
||||
prompt_messages: list[PromptMessage] = Field(default_factory=list)
|
||||
tools: list[PromptMessageTool] | None = Field(default_factory=list[PromptMessageTool])
|
||||
stop: list[str] | None = Field(default_factory=list[str])
|
||||
stream: bool | None = False
|
||||
tools: list[PromptMessageTool] = Field(default_factory=list[PromptMessageTool])
|
||||
stop: list[str] = Field(default_factory=list[str])
|
||||
stream: bool = False
|
||||
|
||||
model_config = ConfigDict(protected_namespaces=())
|
||||
|
||||
|
||||
@ -27,9 +27,9 @@ class DatasourceErrorEvent(BaseDatasourceEvent):
|
||||
class DatasourceCompletedEvent(BaseDatasourceEvent):
|
||||
event: DatasourceStreamEvent = DatasourceStreamEvent.COMPLETED
|
||||
data: Mapping[str, Any] | list = Field(..., description="result")
|
||||
total: int | None = Field(default=0, description="total")
|
||||
completed: int | None = Field(default=0, description="completed")
|
||||
time_consuming: float | None = Field(default=0.0, description="time consuming")
|
||||
total: int = Field(default=0, description="total")
|
||||
completed: int = Field(default=0, description="completed")
|
||||
time_consuming: float = Field(default=0.0, description="time consuming")
|
||||
|
||||
|
||||
class DatasourceProcessingEvent(BaseDatasourceEvent):
|
||||
|
||||
@ -10,7 +10,7 @@ class NotionInfo(BaseModel):
|
||||
"""
|
||||
|
||||
credential_id: str | None = None
|
||||
notion_workspace_id: str | None = ""
|
||||
notion_workspace_id: str = ""
|
||||
notion_obj_id: str
|
||||
notion_page_type: str
|
||||
document: Document | None = None
|
||||
|
||||
@ -38,14 +38,14 @@ class ToolProviderApiEntity(BaseModel):
|
||||
original_credentials: Mapping[str, object] = Field(default_factory=dict)
|
||||
is_team_authorization: bool = False
|
||||
allow_delete: bool = True
|
||||
plugin_id: str | None = Field(default="", description="The plugin id of the tool")
|
||||
plugin_unique_identifier: str | None = Field(default="", description="The unique identifier of the tool")
|
||||
plugin_id: str = Field(default="", description="The plugin id of the tool")
|
||||
plugin_unique_identifier: str = Field(default="", description="The unique identifier of the tool")
|
||||
tools: list[ToolApiEntity] = Field(default_factory=list[ToolApiEntity])
|
||||
labels: list[str] = Field(default_factory=list)
|
||||
# MCP
|
||||
server_url: str | None = Field(default="", description="The server url of the tool")
|
||||
server_url: str = Field(default="", description="The server url of the tool")
|
||||
updated_at: int = Field(default_factory=lambda: int(datetime.now().timestamp()))
|
||||
server_identifier: str | None = Field(default="", description="The server identifier of the MCP tool")
|
||||
server_identifier: str = Field(default="", description="The server identifier of the MCP tool")
|
||||
|
||||
masked_headers: dict[str, str] | None = Field(default=None, description="The masked headers of the MCP tool")
|
||||
original_headers: dict[str, str] | None = Field(default=None, description="The original headers of the MCP tool")
|
||||
|
||||
@ -43,8 +43,8 @@ class TriggerProviderApiEntity(BaseModel):
|
||||
icon_dark: str | None = Field(default=None, description="The dark icon of the trigger provider")
|
||||
tags: list[str] = Field(default_factory=list, description="The tags of the trigger provider")
|
||||
|
||||
plugin_id: str | None = Field(default="", description="The plugin id of the tool")
|
||||
plugin_unique_identifier: str | None = Field(default="", description="The unique identifier of the tool")
|
||||
plugin_id: str = Field(default="", description="The plugin id of the tool")
|
||||
plugin_unique_identifier: str = Field(default="", description="The unique identifier of the tool")
|
||||
|
||||
supported_creation_methods: list[TriggerCreationMethod] = Field(
|
||||
default_factory=list,
|
||||
|
||||
@ -46,7 +46,7 @@ class EventParameter(BaseModel):
|
||||
)
|
||||
template: PluginParameterTemplate | None = Field(default=None, description="The template of the parameter")
|
||||
scope: str | None = None
|
||||
required: bool | None = False
|
||||
required: bool = False
|
||||
multiple: bool | None = Field(
|
||||
default=False,
|
||||
description="Whether the parameter is multiple select, only valid for select or dynamic-select type",
|
||||
|
||||
@ -31,12 +31,12 @@ class SourceMetadata(BaseModel):
|
||||
retriever_from: str = Field(default="workflow", description="Retriever source context")
|
||||
score: float = Field(default=0.0, description="Retrieval relevance score")
|
||||
child_chunks: list[SourceChildChunk] = Field(default_factory=list, description="List of child chunks")
|
||||
segment_hit_count: int | None = Field(default=0, description="Number of times segment was retrieved")
|
||||
segment_word_count: int | None = Field(default=0, description="Word count of the segment")
|
||||
segment_position: int | None = Field(default=0, description="Position of segment in document")
|
||||
segment_hit_count: int = Field(default=0, description="Number of times segment was retrieved")
|
||||
segment_word_count: int = Field(default=0, description="Word count of the segment")
|
||||
segment_position: int = Field(default=0, description="Position of segment in document")
|
||||
segment_index_node_hash: str | None = Field(default=None, description="Hash of index node for the segment")
|
||||
doc_metadata: dict[str, Any] | None = Field(default=None, description="Additional document metadata")
|
||||
position: int | None = Field(default=0, description="Position of the document in the dataset")
|
||||
position: int = Field(default=0, description="Position of the document in the dataset")
|
||||
|
||||
class Config:
|
||||
populate_by_name = True
|
||||
|
||||
@ -36,10 +36,10 @@ class VisualConfig(BaseModel):
|
||||
"""Visual configuration for schedule trigger"""
|
||||
|
||||
# For hourly frequency
|
||||
on_minute: int | None = Field(default=0, ge=0, le=59, description="Minute of the hour (0-59)")
|
||||
on_minute: int = Field(default=0, ge=0, le=59, description="Minute of the hour (0-59)")
|
||||
|
||||
# For daily, weekly, monthly frequencies
|
||||
time: str | None = Field(default="12:00 AM", description="Time in 12-hour format (e.g., '2:30 PM')")
|
||||
time: str = Field(default="12:00 AM", description="Time in 12-hour format (e.g., '2:30 PM')")
|
||||
|
||||
# For weekly frequency
|
||||
weekdays: list[Literal["sun", "mon", "tue", "wed", "thu", "fri", "sat"]] | None = Field(
|
||||
|
||||
@ -728,7 +728,7 @@ class AccountService:
|
||||
account: Account | None = None,
|
||||
email: str | None = None,
|
||||
language: str = "en-US",
|
||||
workspace_name: str | None = "",
|
||||
workspace_name: str = "",
|
||||
):
|
||||
account_email = account.email if account else email
|
||||
if account_email is None:
|
||||
@ -757,7 +757,7 @@ class AccountService:
|
||||
account: Account | None = None,
|
||||
email: str | None = None,
|
||||
language: str = "en-US",
|
||||
workspace_name: str | None = "",
|
||||
workspace_name: str = "",
|
||||
new_owner_email: str = "",
|
||||
):
|
||||
account_email = account.email if account else email
|
||||
@ -778,7 +778,7 @@ class AccountService:
|
||||
account: Account | None = None,
|
||||
email: str | None = None,
|
||||
language: str = "en-US",
|
||||
workspace_name: str | None = "",
|
||||
workspace_name: str = "",
|
||||
):
|
||||
account_email = account.email if account else email
|
||||
if account_email is None:
|
||||
|
||||
@ -11,8 +11,8 @@ class RerankingModelConfig(BaseModel):
|
||||
Reranking Model Config.
|
||||
"""
|
||||
|
||||
reranking_provider_name: str | None = ""
|
||||
reranking_model_name: str | None = ""
|
||||
reranking_provider_name: str = ""
|
||||
reranking_model_name: str = ""
|
||||
|
||||
|
||||
class WeightedScoreConfig(BaseModel):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user