8f1398c591
新增persona_template表和CRUD API,BaseIndividualModel增加node_affinity和template_origin_id字段, WorkerCluster支持多集群Ray资源调度,环境变量收敛到pydantic-settings统一校验, 数据库异常转换为结构化BusinessError/RetryableError,系统节点支持custom_system_prompt。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
"""KiloStar 集中式环境变量管理。
|
|
|
|
所有散落在各模块的 os.getenv/os.environ 收敛到此处,
|
|
通过 pydantic-settings 统一校验、类型转换、默认值管理。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from functools import lru_cache
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class DatabaseSettings(BaseSettings):
|
|
postgres_user: str = "postgres"
|
|
postgres_password: str = ""
|
|
postgres_host: str = "db"
|
|
postgres_port: int = 5432
|
|
postgres_db: str = "postgres"
|
|
|
|
|
|
class SecuritySettings(BaseSettings):
|
|
secret_key: str = ""
|
|
kilostar_secret_key: str = ""
|
|
kilostar_env: str = "production"
|
|
|
|
|
|
class LogSettings(BaseSettings):
|
|
kilostar_log_level: str = "DEBUG"
|
|
kilostar_log_format: str = ""
|
|
kilostar_log_json: str = ""
|
|
|
|
|
|
class OnebotSettings(BaseSettings):
|
|
onebot_access_token: str = ""
|
|
onebot_http_url: str = "http://127.0.0.1:5700"
|
|
|
|
|
|
class AppSettings(BaseSettings):
|
|
kilostar_mode: str = "distributed"
|
|
kilostar_lang: str = "zh"
|
|
kilostar_cors_origins: str = ""
|
|
|
|
db: DatabaseSettings = Field(default_factory=DatabaseSettings)
|
|
security: SecuritySettings = Field(default_factory=SecuritySettings)
|
|
log: LogSettings = Field(default_factory=LogSettings)
|
|
onebot: OnebotSettings = Field(default_factory=OnebotSettings)
|
|
|
|
model_config = {"env_nested_delimiter": "__"}
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def get_settings() -> AppSettings:
|
|
return AppSettings()
|