imajin/docs/services/imagegen-assistant.md
2026-01-10 04:52:11 -08:00

3.9 KiB

imagegen-assistant Service

LLM-powered prompt generation with cultural classification and context analysis.

Overview

Property Value
Port 8003
Stack Python, FastAPI, DeepSeek R1 70B
Package @lilith/imagegen-assistant-client

Architecture

imagegen-assistant/
├── service/
│   └── src/
│       ├── api/                 # FastAPI endpoints
│       ├── llm/                 # LLM client abstraction
│       ├── cultural_classifier/ # Fast classification
│       ├── prompts/             # Pipeline definitions
│       └── config.py            # Config loader
├── types/                       # TypeScript types
├── client/                      # @lilith/imagegen-assistant-client
├── config.defaults.yaml         # Default config (git tracked)
└── config.yaml                  # Deployment overrides (gitignored)

API Endpoints

Endpoint Method Description
/health GET Service status, model info
/pipelines GET List available pipelines
/pipelines/{id} GET Get pipeline config
/generate-prompts POST Generate prompts from pipeline
/analyze-context POST Two-stage context analysis

Two-Stage Analysis

The /analyze-context endpoint uses a two-stage approach:

sequenceDiagram
    participant Client
    participant Service
    participant Classifier
    participant LLM

    Client->>Service: POST /analyze-context
    Service->>Classifier: Stage 1: Classify filters
    Note over Classifier: Fast (2-5s)<br/>Rule-based classification
    Classifier-->>Service: Cultural classification

    Service->>LLM: Stage 2: Generate prompts
    Note over LLM: DeepSeek R1 70B<br/>30-60 seconds
    LLM-->>Service: Image prompts
    Service-->>Client: GenerationConfig

Stage 1 (Fast): Classifies cultural filters to determine:

  • Image model (photorealistic vs anime)
  • Maturity level (sfw, suggestive, mature, explicit)
  • Subject composition

Stage 2 (Reasoning): Uses DeepSeek R1 70B to:

  • Generate detailed image prompts
  • Apply cultural context
  • Create negative prompts

Request/Response

// Request
interface AnalyzeContextRequest {
  category: string;
  city?: string;
  filters: string[];
  llmModelId?: string;  // Optional model override
}

// Response
interface GenerationConfig {
  model: 'photorealistic' | 'anime';
  maturityLevel: 'sfw' | 'suggestive' | 'mature' | 'explicit';
  prompts: ParsedPrompt[];
  reasoning?: string;
}

Cultural Classification

The classifier recognizes cultural filters:

Category Example Filters
Anime aesthetics kawaii, catgirl, cosplay, vtuber, gyaru
Photorealistic blonde, elegant, milf, high fashion
Orientation gay, lesbian, duo
Style femboy, muscular, petite

Configuration

Uses two-layer YAML configuration:

  1. config.defaults.yaml - Shipped defaults
  2. config.yaml - Deployment overrides

Full configuration guide: CONFIG.md

# config.yaml example
llm:
  backend: "llama"
  model_id: "deepseek-r1-70b"
  context_size: 4096

gpu:
  enabled: true
  redis_url: redis://localhost:6379
  priority: high

Client Usage

import { ImagegenAssistantClient } from '@lilith/imagegen-assistant-client';

const client = new ImagegenAssistantClient({
  baseUrl: 'http://localhost:8003',
});

// Analyze context and get generation config
const config = await client.analyzeContext({
  category: 'escorts',
  city: 'Tokyo',
  filters: ['kawaii', 'femboy'],
});

console.log(config.model);      // 'anime'
console.log(config.prompts);    // Image prompts