chore: cleanup and rearrange unclassified configs into feature config groups (#7586)

This commit is contained in:
Bowen Liang
2024-08-23 22:40:07 +08:00
committed by GitHub
parent e3d7c7c6f9
commit 3ace01cfb3
7 changed files with 125 additions and 80 deletions

View File

@@ -1,4 +1,3 @@
from pydantic import Field, computed_field
from pydantic_settings import SettingsConfigDict
from configs.deploy import DeploymentConfig
@@ -24,8 +23,6 @@ class DifyConfig(
# **Before using, please contact business@dify.ai by email to inquire about licensing matters.**
EnterpriseFeatureConfig,
):
DEBUG: bool = Field(default=False, description='whether to enable debug mode.')
model_config = SettingsConfigDict(
# read from dotenv format config file
env_file='.env',
@@ -35,33 +32,7 @@ class DifyConfig(
extra='ignore',
)
CODE_MAX_NUMBER: int = 9223372036854775807
CODE_MIN_NUMBER: int = -9223372036854775808
CODE_MAX_DEPTH: int = 5
CODE_MAX_PRECISION: int = 20
CODE_MAX_STRING_LENGTH: int = 80000
CODE_MAX_STRING_ARRAY_LENGTH: int = 30
CODE_MAX_OBJECT_ARRAY_LENGTH: int = 30
CODE_MAX_NUMBER_ARRAY_LENGTH: int = 1000
HTTP_REQUEST_MAX_CONNECT_TIMEOUT: int = 300
HTTP_REQUEST_MAX_READ_TIMEOUT: int = 600
HTTP_REQUEST_MAX_WRITE_TIMEOUT: int = 600
HTTP_REQUEST_NODE_MAX_BINARY_SIZE: int = 1024 * 1024 * 10
@computed_field
def HTTP_REQUEST_NODE_READABLE_MAX_BINARY_SIZE(self) -> str:
return f'{self.HTTP_REQUEST_NODE_MAX_BINARY_SIZE / 1024 / 1024:.2f}MB'
HTTP_REQUEST_NODE_MAX_TEXT_SIZE: int = 1024 * 1024
@computed_field
def HTTP_REQUEST_NODE_READABLE_MAX_TEXT_SIZE(self) -> str:
return f'{self.HTTP_REQUEST_NODE_MAX_TEXT_SIZE / 1024 / 1024:.2f}MB'
SSRF_PROXY_HTTP_URL: str | None = None
SSRF_PROXY_HTTPS_URL: str | None = None
MODERATION_BUFFER_SIZE: int = Field(default=300, description='The buffer size for moderation.')
MAX_VARIABLE_SIZE: int = Field(default=5 * 1024, description='The maximum size of a variable. default is 5KB.')
# Before adding any config,
# please consider to arrange it in the proper config group of existed or added
# for better readability and maintainability.
# Thanks for your concentration and consideration.

View File

@@ -11,6 +11,11 @@ class DeploymentConfig(BaseSettings):
default='langgenius/dify',
)
DEBUG: bool = Field(
description='whether to enable debug mode.',
default=False,
)
TESTING: bool = Field(
description='',
default=False,

View File

@@ -1,6 +1,6 @@
from typing import Optional
from pydantic import AliasChoices, Field, NonNegativeInt, PositiveInt, computed_field
from pydantic import AliasChoices, Field, NegativeInt, NonNegativeInt, PositiveInt, computed_field
from pydantic_settings import BaseSettings
from configs.feature.hosted_service import HostedServiceConfig
@@ -52,6 +52,46 @@ class CodeExecutionSandboxConfig(BaseSettings):
default='dify-sandbox',
)
CODE_MAX_NUMBER: PositiveInt = Field(
description='max depth for code execution',
default=9223372036854775807,
)
CODE_MIN_NUMBER: NegativeInt = Field(
description='',
default=-9223372036854775807,
)
CODE_MAX_DEPTH: PositiveInt = Field(
description='max depth for code execution',
default=5,
)
CODE_MAX_PRECISION: PositiveInt = Field(
description='max precision digits for float type in code execution',
default=20,
)
CODE_MAX_STRING_LENGTH: PositiveInt = Field(
description='max string length for code execution',
default=80000,
)
CODE_MAX_STRING_ARRAY_LENGTH: PositiveInt = Field(
description='',
default=30,
)
CODE_MAX_OBJECT_ARRAY_LENGTH: PositiveInt = Field(
description='',
default=30,
)
CODE_MAX_NUMBER_ARRAY_LENGTH: PositiveInt = Field(
description='',
default=1000,
)
class EndpointConfig(BaseSettings):
"""
@@ -157,6 +197,41 @@ class HttpConfig(BaseSettings):
def WEB_API_CORS_ALLOW_ORIGINS(self) -> list[str]:
return self.inner_WEB_API_CORS_ALLOW_ORIGINS.split(',')
HTTP_REQUEST_MAX_CONNECT_TIMEOUT: NonNegativeInt = Field(
description='',
default=300,
)
HTTP_REQUEST_MAX_READ_TIMEOUT: NonNegativeInt = Field(
description='',
default=600,
)
HTTP_REQUEST_MAX_WRITE_TIMEOUT: NonNegativeInt = Field(
description='',
default=600,
)
HTTP_REQUEST_NODE_MAX_BINARY_SIZE: PositiveInt = Field(
description='',
default=10 * 1024 * 1024,
)
HTTP_REQUEST_NODE_MAX_TEXT_SIZE: PositiveInt = Field(
description='',
default=1 * 1024 * 1024,
)
SSRF_PROXY_HTTP_URL: Optional[str] = Field(
description='HTTP URL for SSRF proxy',
default=None,
)
SSRF_PROXY_HTTPS_URL: Optional[str] = Field(
description='HTTPS URL for SSRF proxy',
default=None,
)
class InnerAPIConfig(BaseSettings):
"""
@@ -255,6 +330,11 @@ class WorkflowConfig(BaseSettings):
default=5,
)
MAX_VARIABLE_SIZE: PositiveInt = Field(
description='The maximum size in bytes of a variable. default to 5KB.',
default=5 * 1024,
)
class OAuthConfig(BaseSettings):
"""
@@ -291,8 +371,7 @@ class ModerationConfig(BaseSettings):
Moderation in app configs.
"""
# todo: to be clarified in usage and unit
OUTPUT_MODERATION_BUFFER_SIZE: PositiveInt = Field(
MODERATION_BUFFER_SIZE: PositiveInt = Field(
description='buffer size for moderation',
default=300,
)
@@ -444,7 +523,6 @@ class CeleryBeatConfig(BaseSettings):
class PositionConfig(BaseSettings):
POSITION_PROVIDER_PINS: str = Field(
description='The heads of model providers',
default='',