hp-studios-ai-content-agent/backend/app/cli/seed.py
DJP 72c8a0d0fe Initial import — HP Studios AI Content Agent
Full-stack app that turns HP customer briefs (master asset + regional
supporting docs) into a set of branded Word deliverables via a RAG +
agent pipeline.

Stack
- FastAPI + SQLAlchemy + pgvector + RQ (backend, Python 3.12)
- React + Vite + TypeScript + Tailwind + TanStack Query (frontend)
- Claude Opus 4.7 (generation) + Haiku 4.5 (translation/OCR)
- Voyage voyage-3 or OpenAI text-embedding-3-small (embeddings)
- python-docx (branded Word output, Montserrat + HP blue)
- Docker Compose (5 services)

Features
- 6 built-in deliverable types (leadership themes, regional enrichment,
  LinkedIn posts, webinar spec, infographic specs, ABM enablement)
- Data-driven deliverable types: admins add new types at runtime via
  prompt + JSON schema + template_json — no code, no deploy
- Generic schema-driven review form + generic Word template renderer
- Document ingestion pipeline with translation, chunking, pgvector RAG
- Pluggable auth provider (password now, Entra SSO later); admin/user roles
- Re-roll / retry on every deliverable; cascading delete; brief editing;
  inline document upload; progress hints; router-level ErrorBoundary
- Admin panel with test-render preview for new deliverable types
- Help page at /help with architecture overview and usage guide

82 backend tests passing, 18 skipped (gated live-API tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 17:11:25 -04:00

59 lines
1.5 KiB
Python

from __future__ import annotations
"""CLI script — seed the first admin user.
Usage:
python -m app.cli.seed
Reads credentials from env vars:
SEED_ADMIN_EMAIL (default: admin@example.com)
SEED_ADMIN_PASSWORD (default: changeme)
SEED_ADMIN_NAME (default: Admin)
If a user with that email already exists the script is a no-op.
Otherwise it creates the user and prints the credentials once.
"""
import sys
def main() -> None:
from app.core.config import settings
from app.core.security import hash_password
from app.db.models import User
from app.db.session import SessionLocal
email = settings.SEED_ADMIN_EMAIL
password = settings.SEED_ADMIN_PASSWORD
name = settings.SEED_ADMIN_NAME
db = SessionLocal()
try:
existing = db.query(User).filter(User.email == email).first()
if existing:
print(f"[seed] User '{email}' already exists — nothing to do.", file=sys.stderr)
return
user = User(
email=email,
name=name,
password_hash=hash_password(password),
role="admin",
)
db.add(user)
db.commit()
print("=" * 60)
print("Admin user created:")
print(f" Email: {email}")
print(f" Password: {password}")
print(f" Role: admin")
print(f" ID: {user.id}")
print("=" * 60)
print("IMPORTANT: change the password after first login.")
finally:
db.close()
if __name__ == "__main__":
main()