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 contextStorySegmentGenerator
: Generates narrative segmentsMetadataGenerator
: Handles metadata (time, location, choices)ImagePromptGenerator
: Creates prompts for images
Services
MistralService
: Interface with Mistral APIGameStateManager
: Game state managementAudioService
: Narration management
π οΈ Installation
Prerequisites:
python 3.10+ poetry
Installation:
cd server poetry install
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
Initialization
- Universe creation
- Initial context definition
- Base story generation
Game Loop
- Narrative segment generation
- Choice creation
- Metadata updates
- Image prompt generation
State Management
- Progress tracking
- Choice history
- World state
π API Endpoints
POST /game/start
: Start a new gamePOST /game/choice
: Submit a choiceGET /game/state
: Get current statePOST /game/generate-image
: Generate an imagePOST /game/narrate
: Generate audio narration
π§ͺ Testing
# Unit tests
poetry run pytest
# Coverage tests
poetry run pytest --cov
# Integration tests
poetry run pytest tests/integration