2026-07-21 09:23:43 +08:00
|
|
|
|
from dataclasses import dataclass
|
2026-07-16 13:47:37 +08:00
|
|
|
|
from functools import lru_cache
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _int_env(name: str, default: int) -> int:
|
|
|
|
|
|
raw = os.getenv(name)
|
|
|
|
|
|
if raw is None or raw == "":
|
|
|
|
|
|
return default
|
|
|
|
|
|
return int(raw)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-07-21 11:06:34 +08:00
|
|
|
|
def _list_env(name: str, default: list[str]) -> list[str]:
|
|
|
|
|
|
raw = os.getenv(name)
|
|
|
|
|
|
if raw is None or raw.strip() == "":
|
|
|
|
|
|
return default
|
|
|
|
|
|
return [item.strip() for item in raw.split(",") if item.strip()]
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-07-16 13:47:37 +08:00
|
|
|
|
@dataclass(frozen=True)
|
|
|
|
|
|
class Settings:
|
|
|
|
|
|
app_name: str = os.getenv("APP_NAME", "YG Fine-Tune Platform API")
|
|
|
|
|
|
app_env: str = os.getenv("APP_ENV", "local")
|
2026-07-21 10:09:36 +08:00
|
|
|
|
route_prefix: str = os.getenv("MODELTF_ROUTE_PREFIX", "/modelTF")
|
2026-07-21 09:23:43 +08:00
|
|
|
|
app_mode: str = os.getenv("APP_MODE", "local")
|
2026-07-21 10:55:44 +08:00
|
|
|
|
database_url: str = os.getenv("DATABASE_URL", "postgresql+psycopg://yg_ft:change_me@localhost:15432/yg_ft")
|
2026-07-21 11:06:34 +08:00
|
|
|
|
cors_allow_origins: list[str] = None # type: ignore[assignment]
|
2026-07-21 10:55:44 +08:00
|
|
|
|
compute_mode: str = os.getenv("COMPUTE_MODE", "real")
|
2026-07-21 09:23:43 +08:00
|
|
|
|
compute_status_sync_mode: str = os.getenv("COMPUTE_STATUS_SYNC_MODE", "polling")
|
|
|
|
|
|
compute_poll_interval_seconds: int = _int_env("COMPUTE_POLL_INTERVAL_SECONDS", 3)
|
2026-07-22 17:32:59 +08:00
|
|
|
|
compute_request_timeout_seconds: int = _int_env("COMPUTE_REQUEST_TIMEOUT_SECONDS", 5)
|
|
|
|
|
|
compute_service_token: str = os.getenv("COMPUTE_SERVICE_TOKEN", "")
|
2026-07-16 13:47:37 +08:00
|
|
|
|
log_level: str = os.getenv("LOG_LEVEL", "INFO")
|
|
|
|
|
|
log_dir: str = os.getenv("LOG_DIR", "./logs")
|
|
|
|
|
|
log_file_prefix: str = os.getenv("LOG_FILE_PREFIX", "backend")
|
|
|
|
|
|
log_error_file_prefix: str = os.getenv("LOG_ERROR_FILE_PREFIX", "error")
|
|
|
|
|
|
log_max_bytes: int = _int_env("LOG_MAX_BYTES", 20 * 1024 * 1024)
|
|
|
|
|
|
log_retention_days: int = _int_env("LOG_RETENTION_DAYS", 10)
|
|
|
|
|
|
|
2026-07-21 11:06:34 +08:00
|
|
|
|
def __post_init__(self) -> None:
|
|
|
|
|
|
object.__setattr__(
|
|
|
|
|
|
self,
|
|
|
|
|
|
"cors_allow_origins",
|
|
|
|
|
|
_list_env(
|
|
|
|
|
|
"CORS_ALLOW_ORIGINS",
|
|
|
|
|
|
[
|
|
|
|
|
|
"http://localhost:16801",
|
|
|
|
|
|
"http://127.0.0.1:16801",
|
|
|
|
|
|
"http://localhost:17861",
|
|
|
|
|
|
"http://127.0.0.1:17861",
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-07-16 13:47:37 +08:00
|
|
|
|
|
|
|
|
|
|
@lru_cache
|
|
|
|
|
|
def get_settings() -> Settings:
|
|
|
|
|
|
return Settings()
|
2026-07-21 09:23:43 +08:00
|
|
|
|
|