48 lines
2.2 KiB
Python
48 lines
2.2 KiB
Python
"""Configuration for the content moderation inference API."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# ── Paths ─────────────────────────────────────────────────────────────────────
|
|
|
|
# Root of the content-moderation application (two levels up from services/inference-api/)
|
|
_SERVICE_DIR = Path(__file__).parent
|
|
APP_ROOT = _SERVICE_DIR.parents[1]
|
|
|
|
MODELS_ROOT = APP_ROOT / "models"
|
|
|
|
# Runtime override: set CM_MODEL_DIR to an absolute path containing model_fp16.onnx or model.onnx
|
|
CM_MODEL_DIR_ENV: str = os.environ.get("CM_MODEL_DIR", "")
|
|
|
|
# ── Inference ─────────────────────────────────────────────────────────────────
|
|
|
|
MAX_SEQ_LENGTH: int = 256
|
|
BATCH_SIZE_LIMIT: int = 64
|
|
|
|
# ── API ───────────────────────────────────────────────────────────────────────
|
|
|
|
API_HOST: str = os.environ.get("CM_API_HOST", "0.0.0.0")
|
|
API_PORT: int = int(os.environ.get("CM_API_PORT", "3501"))
|
|
|
|
# Admin token for model/reload endpoint — required in production.
|
|
# Set CM_ADMIN_TOKEN env var. If empty the endpoint is disabled.
|
|
ADMIN_TOKEN: str = os.environ.get("CM_ADMIN_TOKEN", "")
|
|
|
|
# ── Feedback store ────────────────────────────────────────────────────────────
|
|
|
|
_default_feedback_path = _SERVICE_DIR / "feedback.jsonl"
|
|
FEEDBACK_STORE_PATH: Path = Path(
|
|
os.environ.get("CM_FEEDBACK_STORE", str(_default_feedback_path))
|
|
)
|
|
|
|
# ── Content-type to context-prefix mapping ───────────────────────────────────
|
|
|
|
CONTENT_TYPE_PREFIXES: dict[str, str] = {
|
|
"message": "[ADULT][MESSAGE]",
|
|
"bio": "[ADULT][BIO]",
|
|
"listing": "[ADULT][LISTING]",
|
|
"review": "[ADULT][REVIEW]",
|
|
"coop_description": "[ADULT][COOP]",
|
|
}
|