Backend for the Comic Book Generator, powered by Mistral AI for story generation.
The server is built around several specialized AI generators:
UniverseGenerator: Creates the universe and initial contextStorySegmentGenerator: Generates narrative segmentsMetadataGenerator: Handles metadata (time, location, choices)ImagePromptGenerator: Creates prompts for images
MistralService: Interface with Mistral APIGameStateManager: Game state managementAudioService: Narration management
-
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
poetry run dev# 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-contextserver/
├── 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
-
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
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
# Unit tests
poetry run pytest
# Coverage tests
poetry run pytest --cov
# Integration tests
poetry run pytest tests/integration