Files
postgenerator/backend/config.py
Michele 50d5708016 feat(01-01): Backend FastAPI skeleton + Docker build config
- FastAPI app with SPAStaticFiles catch-all (root_path NOT in constructor)
- config.py with DATA_PATH, PROMPTS_PATH, OUTPUTS_PATH, CAMPAIGNS_PATH, CONFIG_PATH
- Startup lifespan creates data directories automatically
- Health endpoint: GET /api/health -> {"status": "ok"}
- Dockerfile multi-stage: node:22-slim builds React, python:3.12-slim serves API+SPA
- --root-path /postgenerator set in Uvicorn CMD only (avoids Pitfall #4)
- docker-compose.yml: lab-postgenerator-app, proxy_net, named volume for data persistence
- requirements.txt with pinned versions: fastapi[standard]==0.135.1, anthropic==0.84.0
2026-03-08 01:51:41 +01:00

54 lines
1.5 KiB
Python

"""Centralized configuration and path constants for PostGenerator."""
import os
from pathlib import Path
from dataclasses import dataclass
# ---------------------------------------------------------------------------
# Path constants (read from env, defaulting to ./data for local dev)
# ---------------------------------------------------------------------------
DATA_PATH = Path(os.getenv("DATA_PATH", "./data"))
PROMPTS_PATH = DATA_PATH / "prompts"
OUTPUTS_PATH = DATA_PATH / "outputs"
CAMPAIGNS_PATH = DATA_PATH / "campaigns"
CONFIG_PATH = DATA_PATH / "config"
# ---------------------------------------------------------------------------
# App settings
# ---------------------------------------------------------------------------
@dataclass
class Settings:
anthropic_api_key: str
llm_model: str
data_path: Path
prompts_path: Path
outputs_path: Path
campaigns_path: Path
config_path: Path
def get_settings() -> Settings:
"""Load settings from environment variables."""
api_key = os.getenv("ANTHROPIC_API_KEY", "")
if not api_key:
import warnings
warnings.warn(
"ANTHROPIC_API_KEY not set — generation endpoints will fail",
RuntimeWarning,
stacklevel=2,
)
return Settings(
anthropic_api_key=api_key,
llm_model=os.getenv("LLM_MODEL", "claude-sonnet-4-5"),
data_path=DATA_PATH,
prompts_path=PROMPTS_PATH,
outputs_path=OUTPUTS_PATH,
campaigns_path=CAMPAIGNS_PATH,
config_path=CONFIG_PATH,
)