Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
"""Creem Moderation API provider (kept available, not the default).
|
|
|
|
Selected with ``MENIVOR_MODERATION_PROVIDER=creem``. Needs ``CREEM_API_KEY``
|
|
(``creem_`` live, ``creem_test_`` sandbox); ``CREEM_MODERATION_URL`` overrides
|
|
the endpoint. See https://docs.creem.io/features/moderation.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import Any
|
|
|
|
import httpx
|
|
|
|
from app.core.moderation_types import DECISIONS, ModerationResult, ModerationUnavailable
|
|
|
|
LIVE_URL = "https://api.creem.io/v1/moderation/prompt"
|
|
SANDBOX_URL = "https://test-api.creem.io/v1/moderation/prompt"
|
|
NAME = "creem"
|
|
|
|
|
|
def api_key() -> str:
|
|
return (os.getenv("CREEM_API_KEY") or "").strip()
|
|
|
|
|
|
def configured() -> bool:
|
|
return bool(api_key())
|
|
|
|
|
|
def endpoint(key: str) -> str:
|
|
override = (os.getenv("CREEM_MODERATION_URL") or "").strip()
|
|
if override:
|
|
return override
|
|
return SANDBOX_URL if key.startswith("creem_test_") else LIVE_URL
|
|
|
|
|
|
def check(prompt: str, *, external_id: str = "", timeout_s: float) -> ModerationResult:
|
|
"""Call the Creem Moderation API once. Raises ``ModerationUnavailable``."""
|
|
key = api_key()
|
|
if not key:
|
|
raise ModerationUnavailable("CREEM_API_KEY is not configured")
|
|
payload: dict[str, Any] = {"prompt": prompt}
|
|
if external_id:
|
|
payload["external_id"] = external_id[:128]
|
|
try:
|
|
response = httpx.post(
|
|
endpoint(key),
|
|
headers={"x-api-key": key, "content-type": "application/json"},
|
|
json=payload,
|
|
timeout=timeout_s,
|
|
)
|
|
except httpx.HTTPError as exc:
|
|
raise ModerationUnavailable(f"transport: {type(exc).__name__}") from exc
|
|
if response.status_code != 200:
|
|
raise ModerationUnavailable(f"status {response.status_code}")
|
|
try:
|
|
data = response.json()
|
|
except ValueError as exc:
|
|
raise ModerationUnavailable("non-json body") from exc
|
|
decision = str((data or {}).get("decision") or "").lower()
|
|
if decision not in DECISIONS:
|
|
raise ModerationUnavailable(f"unexpected decision {decision!r}")
|
|
return ModerationResult(
|
|
decision=decision, moderation_id=str(data.get("id") or ""), provider=NAME
|
|
)
|