tfrere's picture
update
ede321f

Comic Book Generator - Server

Backend for the Comic Book Generator, powered by Mistral AI for story generation.

🧠 Architecture

The server is built around several specialized AI generators:

Generators

  • UniverseGenerator: Creates the universe and initial context
  • StorySegmentGenerator: Generates narrative segments
  • MetadataGenerator: Handles metadata (time, location, choices)
  • ImagePromptGenerator: Creates prompts for images

Services

  • MistralService: Interface with Mistral API
  • GameStateManager: Game state management
  • AudioService: Narration management

πŸ› οΈ Installation

  1. Prerequisites:

    python 3.10+
    poetry
    
  2. Installation:

    cd server
    poetry install
    
  3. Configuration:

    cp .env.example .env
    # Add your Mistral API key to .env
    # Add your Hugging Face endpoint URL to .env
    

    Required environment variables:

    MISTRAL_API_KEY=your_mistral_api_key
    HF_API_ENDPOINT=your_huggingface_endpoint_url
    

πŸš€ Usage

Start the Server

poetry run dev

Game Testing

# Interactive mode
poetry run test-game

# Automatic mode
poetry run test-game --auto

# Automatic mode with parameters
poetry run test-game --auto --max-turns 20 --show-context

πŸ“ Project Structure

server/
β”œβ”€β”€ api/            # FastAPI routes and models
β”‚   β”œβ”€β”€ models.py   # Pydantic models
β”‚   └── routes.py   # API endpoints
β”œβ”€β”€ core/           # Business logic
β”‚   β”œβ”€β”€ generators/ # AI generators
β”‚   └── prompts/    # Prompt templates
β”œβ”€β”€ services/       # External services
└── scripts/        # Utility scripts

πŸ”„ Generation Workflow

  1. Initialization

    • Universe creation
    • Initial context definition
    • Base story generation
  2. Game Loop

    • Narrative segment generation
    • Choice creation
    • Metadata updates
    • Image prompt generation
  3. State Management

    • Progress tracking
    • Choice history
    • World state

πŸ“ API Endpoints

  • POST /game/start: Start a new game
  • POST /game/choice: Submit a choice
  • GET /game/state: Get current state
  • POST /game/generate-image: Generate an image
  • POST /game/narrate: Generate audio narration

πŸ§ͺ Testing

# Unit tests
poetry run pytest

# Coverage tests
poetry run pytest --cov

# Integration tests
poetry run pytest tests/integration