mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
chore: use singular style in config class name (#5489)
This commit is contained in:
parent
9a5c423d59
commit
8890978ad3
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
|
||||
from configs.app_configs import DifyConfigs
|
||||
from configs.app_config import DifyConfig
|
||||
|
||||
if not os.environ.get("DEBUG") or os.environ.get("DEBUG", "false").lower() != 'true':
|
||||
from gevent import monkey
|
||||
|
@ -83,7 +83,7 @@ def create_flask_app_with_configs() -> Flask:
|
|||
"""
|
||||
dify_app = DifyApp(__name__)
|
||||
dify_app.config.from_object(Config())
|
||||
dify_app.config.from_mapping(DifyConfigs().model_dump())
|
||||
dify_app.config.from_mapping(DifyConfig().model_dump())
|
||||
return dify_app
|
||||
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
from configs.deploy import DeploymentConfigs
|
||||
from configs.enterprise import EnterpriseFeatureConfigs
|
||||
from configs.extra import ExtraServiceConfigs
|
||||
from configs.feature import FeatureConfigs
|
||||
from configs.middleware import MiddlewareConfigs
|
||||
from configs.deploy import DeploymentConfig
|
||||
from configs.enterprise import EnterpriseFeatureConfig
|
||||
from configs.extra import ExtraServiceConfig
|
||||
from configs.feature import FeatureConfig
|
||||
from configs.middleware import MiddlewareConfig
|
||||
from configs.packaging import PackagingInfo
|
||||
|
||||
|
||||
class DifyConfigs(
|
||||
class DifyConfig(
|
||||
# based on pydantic-settings
|
||||
BaseSettings,
|
||||
|
||||
|
@ -16,20 +16,20 @@ class DifyConfigs(
|
|||
PackagingInfo,
|
||||
|
||||
# Deployment configs
|
||||
DeploymentConfigs,
|
||||
DeploymentConfig,
|
||||
|
||||
# Feature configs
|
||||
FeatureConfigs,
|
||||
FeatureConfig,
|
||||
|
||||
# Middleware configs
|
||||
MiddlewareConfigs,
|
||||
MiddlewareConfig,
|
||||
|
||||
# Extra service configs
|
||||
ExtraServiceConfigs,
|
||||
ExtraServiceConfig,
|
||||
|
||||
# Enterprise feature configs
|
||||
# **Before using, please contact business@dify.ai by email to inquire about licensing matters.**
|
||||
EnterpriseFeatureConfigs,
|
||||
EnterpriseFeatureConfig,
|
||||
):
|
||||
|
||||
model_config = SettingsConfigDict(
|
|
@ -1,7 +1,7 @@
|
|||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class DeploymentConfigs(BaseModel):
|
||||
class DeploymentConfig(BaseModel):
|
||||
"""
|
||||
Deployment configs
|
||||
"""
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class EnterpriseFeatureConfigs(BaseModel):
|
||||
class EnterpriseFeatureConfig(BaseModel):
|
||||
"""
|
||||
Enterprise feature configs.
|
||||
**Before using, please contact business@dify.ai by email to inquire about licensing matters.**
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from pydantic import BaseModel
|
||||
|
||||
from configs.extra.notion_configs import NotionConfigs
|
||||
from configs.extra.sentry_configs import SentryConfigs
|
||||
from configs.extra.notion_config import NotionConfig
|
||||
from configs.extra.sentry_config import SentryConfig
|
||||
|
||||
|
||||
class ExtraServiceConfigs(
|
||||
class ExtraServiceConfig(
|
||||
# place the configs in alphabet order
|
||||
NotionConfigs,
|
||||
SentryConfigs,
|
||||
NotionConfig,
|
||||
SentryConfig,
|
||||
):
|
||||
pass
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Optional
|
|||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class NotionConfigs(BaseModel):
|
||||
class NotionConfig(BaseModel):
|
||||
"""
|
||||
Notion integration configs
|
||||
"""
|
|
@ -3,7 +3,7 @@ from typing import Optional
|
|||
from pydantic import BaseModel, Field, NonNegativeFloat
|
||||
|
||||
|
||||
class SentryConfigs(BaseModel):
|
||||
class SentryConfig(BaseModel):
|
||||
"""
|
||||
Sentry configs
|
||||
"""
|
|
@ -3,7 +3,7 @@ from typing import Optional
|
|||
from pydantic import AliasChoices, BaseModel, Field, NonNegativeInt, PositiveInt
|
||||
|
||||
|
||||
class SecurityConfigs(BaseModel):
|
||||
class SecurityConfig(BaseModel):
|
||||
"""
|
||||
Secret Key configs
|
||||
"""
|
||||
|
@ -16,7 +16,7 @@ class SecurityConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class AppExecutionConfigs(BaseModel):
|
||||
class AppExecutionConfig(BaseModel):
|
||||
"""
|
||||
App Execution configs
|
||||
"""
|
||||
|
@ -26,7 +26,7 @@ class AppExecutionConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class CodeExecutionSandboxConfigs(BaseModel):
|
||||
class CodeExecutionSandboxConfig(BaseModel):
|
||||
"""
|
||||
Code Execution Sandbox configs
|
||||
"""
|
||||
|
@ -41,7 +41,7 @@ class CodeExecutionSandboxConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class EndpointConfigs(BaseModel):
|
||||
class EndpointConfig(BaseModel):
|
||||
"""
|
||||
Module URL configs
|
||||
"""
|
||||
|
@ -70,7 +70,7 @@ class EndpointConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class FileAccessConfigs(BaseModel):
|
||||
class FileAccessConfig(BaseModel):
|
||||
"""
|
||||
File Access configs
|
||||
"""
|
||||
|
@ -89,7 +89,7 @@ class FileAccessConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class FileUploadConfigs(BaseModel):
|
||||
class FileUploadConfig(BaseModel):
|
||||
"""
|
||||
File Uploading configs
|
||||
"""
|
||||
|
@ -114,7 +114,7 @@ class FileUploadConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class HttpConfigs(BaseModel):
|
||||
class HttpConfig(BaseModel):
|
||||
"""
|
||||
HTTP configs
|
||||
"""
|
||||
|
@ -124,7 +124,7 @@ class HttpConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class InnerAPIConfigs(BaseModel):
|
||||
class InnerAPIConfig(BaseModel):
|
||||
"""
|
||||
Inner API configs
|
||||
"""
|
||||
|
@ -139,7 +139,7 @@ class InnerAPIConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class LoggingConfigs(BaseModel):
|
||||
class LoggingConfig(BaseModel):
|
||||
"""
|
||||
Logging configs
|
||||
"""
|
||||
|
@ -171,7 +171,7 @@ class LoggingConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class ModelLoadBalanceConfigs(BaseModel):
|
||||
class ModelLoadBalanceConfig(BaseModel):
|
||||
"""
|
||||
Model load balance configs
|
||||
"""
|
||||
|
@ -181,7 +181,7 @@ class ModelLoadBalanceConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class BillingConfigs(BaseModel):
|
||||
class BillingConfig(BaseModel):
|
||||
"""
|
||||
Platform Billing Configurations
|
||||
"""
|
||||
|
@ -191,7 +191,7 @@ class BillingConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class UpdateConfigs(BaseModel):
|
||||
class UpdateConfig(BaseModel):
|
||||
"""
|
||||
Update configs
|
||||
"""
|
||||
|
@ -201,7 +201,7 @@ class UpdateConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class WorkflowConfigs(BaseModel):
|
||||
class WorkflowConfig(BaseModel):
|
||||
"""
|
||||
Workflow feature configs
|
||||
"""
|
||||
|
@ -222,7 +222,7 @@ class WorkflowConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class OAuthConfigs(BaseModel):
|
||||
class OAuthConfig(BaseModel):
|
||||
"""
|
||||
oauth configs
|
||||
"""
|
||||
|
@ -252,7 +252,7 @@ class OAuthConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class ModerationConfigs(BaseModel):
|
||||
class ModerationConfig(BaseModel):
|
||||
"""
|
||||
Moderation in app configs.
|
||||
"""
|
||||
|
@ -264,7 +264,7 @@ class ModerationConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class ToolConfigs(BaseModel):
|
||||
class ToolConfig(BaseModel):
|
||||
"""
|
||||
Tool configs
|
||||
"""
|
||||
|
@ -275,7 +275,7 @@ class ToolConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class MailConfigs(BaseModel):
|
||||
class MailConfig(BaseModel):
|
||||
"""
|
||||
Mail Configurations
|
||||
"""
|
||||
|
@ -331,7 +331,7 @@ class MailConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class RagEtlConfigs(BaseModel):
|
||||
class RagEtlConfig(BaseModel):
|
||||
"""
|
||||
RAG ETL Configurations.
|
||||
"""
|
||||
|
@ -357,7 +357,7 @@ class RagEtlConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class DataSetConfigs(BaseModel):
|
||||
class DataSetConfig(BaseModel):
|
||||
"""
|
||||
Dataset configs
|
||||
"""
|
||||
|
@ -368,7 +368,7 @@ class DataSetConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class WorkspaceConfigs(BaseModel):
|
||||
class WorkspaceConfig(BaseModel):
|
||||
"""
|
||||
Workspace configs
|
||||
"""
|
||||
|
@ -379,7 +379,7 @@ class WorkspaceConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class IndexingConfigs(BaseModel):
|
||||
class IndexingConfig(BaseModel):
|
||||
"""
|
||||
Indexing configs.
|
||||
"""
|
||||
|
@ -390,36 +390,36 @@ class IndexingConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class ImageFormatConfigs(BaseModel):
|
||||
class ImageFormatConfig(BaseModel):
|
||||
MULTIMODAL_SEND_IMAGE_FORMAT: str = Field(
|
||||
description='multi model send image format, support base64, url, default is base64',
|
||||
default='base64',
|
||||
)
|
||||
|
||||
|
||||
class FeatureConfigs(
|
||||
class FeatureConfig(
|
||||
# place the configs in alphabet order
|
||||
AppExecutionConfigs,
|
||||
BillingConfigs,
|
||||
CodeExecutionSandboxConfigs,
|
||||
DataSetConfigs,
|
||||
EndpointConfigs,
|
||||
FileAccessConfigs,
|
||||
FileUploadConfigs,
|
||||
HttpConfigs,
|
||||
ImageFormatConfigs,
|
||||
InnerAPIConfigs,
|
||||
IndexingConfigs,
|
||||
LoggingConfigs,
|
||||
MailConfigs,
|
||||
ModelLoadBalanceConfigs,
|
||||
ModerationConfigs,
|
||||
OAuthConfigs,
|
||||
RagEtlConfigs,
|
||||
SecurityConfigs,
|
||||
ToolConfigs,
|
||||
UpdateConfigs,
|
||||
WorkflowConfigs,
|
||||
WorkspaceConfigs,
|
||||
AppExecutionConfig,
|
||||
BillingConfig,
|
||||
CodeExecutionSandboxConfig,
|
||||
DataSetConfig,
|
||||
EndpointConfig,
|
||||
FileAccessConfig,
|
||||
FileUploadConfig,
|
||||
HttpConfig,
|
||||
ImageFormatConfig,
|
||||
InnerAPIConfig,
|
||||
IndexingConfig,
|
||||
LoggingConfig,
|
||||
MailConfig,
|
||||
ModelLoadBalanceConfig,
|
||||
ModerationConfig,
|
||||
OAuthConfig,
|
||||
RagEtlConfig,
|
||||
SecurityConfig,
|
||||
ToolConfig,
|
||||
UpdateConfig,
|
||||
WorkflowConfig,
|
||||
WorkspaceConfig,
|
||||
):
|
||||
pass
|
||||
|
|
|
@ -2,7 +2,7 @@ from typing import Optional
|
|||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from configs.middleware.redis_configs import RedisConfigs
|
||||
from configs.middleware.redis_config import RedisConfig
|
||||
from configs.middleware.vdb.chroma_configs import ChromaConfigs
|
||||
from configs.middleware.vdb.milvus_configs import MilvusConfigs
|
||||
from configs.middleware.vdb.opensearch_configs import OpenSearchConfigs
|
||||
|
@ -44,10 +44,10 @@ class KeywordStoreConfigs(BaseModel):
|
|||
)
|
||||
|
||||
|
||||
class MiddlewareConfigs(
|
||||
class MiddlewareConfig(
|
||||
# place the configs in alphabet order
|
||||
KeywordStoreConfigs,
|
||||
RedisConfigs,
|
||||
RedisConfig,
|
||||
StorageConfigs,
|
||||
|
||||
# configs of vdb and vdb providers
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Optional
|
|||
from pydantic import BaseModel, Field, NonNegativeInt, PositiveInt
|
||||
|
||||
|
||||
class RedisConfigs(BaseModel):
|
||||
class RedisConfig(BaseModel):
|
||||
"""
|
||||
Redis configs
|
||||
"""
|
|
@ -3,7 +3,7 @@ from textwrap import dedent
|
|||
import pytest
|
||||
from flask import Flask
|
||||
|
||||
from configs.app_configs import DifyConfigs
|
||||
from configs.app_config import DifyConfig
|
||||
|
||||
EXAMPLE_ENV_FILENAME = '.env'
|
||||
|
||||
|
@ -19,32 +19,32 @@ def example_env_file(tmp_path, monkeypatch) -> str:
|
|||
return str(file_path)
|
||||
|
||||
|
||||
def test_dify_configs_undefined_entry(example_env_file):
|
||||
def test_dify_config_undefined_entry(example_env_file):
|
||||
# load dotenv file with pydantic-settings
|
||||
settings = DifyConfigs(_env_file=example_env_file)
|
||||
config = DifyConfig(_env_file=example_env_file)
|
||||
|
||||
# entries not defined in app settings
|
||||
with pytest.raises(TypeError):
|
||||
# TypeError: 'AppSettings' object is not subscriptable
|
||||
assert settings['LOG_LEVEL'] == 'INFO'
|
||||
assert config['LOG_LEVEL'] == 'INFO'
|
||||
|
||||
|
||||
def test_dify_configs(example_env_file):
|
||||
def test_dify_config(example_env_file):
|
||||
# load dotenv file with pydantic-settings
|
||||
settings = DifyConfigs(_env_file=example_env_file)
|
||||
config = DifyConfig(_env_file=example_env_file)
|
||||
|
||||
# constant values
|
||||
assert settings.COMMIT_SHA == ''
|
||||
assert config.COMMIT_SHA == ''
|
||||
|
||||
# default values
|
||||
assert settings.EDITION == 'SELF_HOSTED'
|
||||
assert settings.API_COMPRESSION_ENABLED is False
|
||||
assert settings.SENTRY_TRACES_SAMPLE_RATE == 1.0
|
||||
assert config.EDITION == 'SELF_HOSTED'
|
||||
assert config.API_COMPRESSION_ENABLED is False
|
||||
assert config.SENTRY_TRACES_SAMPLE_RATE == 1.0
|
||||
|
||||
|
||||
def test_flask_configs(example_env_file):
|
||||
flask_app = Flask('app')
|
||||
flask_app.config.from_mapping(DifyConfigs(_env_file=example_env_file).model_dump())
|
||||
flask_app.config.from_mapping(DifyConfig(_env_file=example_env_file).model_dump())
|
||||
config = flask_app.config
|
||||
|
||||
# configs read from dotenv directly
|
Loading…
Reference in New Issue
Block a user