# 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: ```bash python 3.10+ poetry ``` 2. Installation: ```bash cd server poetry install ``` 3. Configuration: ```bash cp .env.example .env # Add your Mistral API key to .env # Add your Hugging Face endpoint URL to .env ``` Required environment variables: ```env MISTRAL_API_KEY=your_mistral_api_key HF_API_ENDPOINT=your_huggingface_endpoint_url ``` ## ๐Ÿš€ Usage ### Start the Server ```bash poetry run dev ``` ### Game Testing ```bash # 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 ```bash # Unit tests poetry run pytest # Coverage tests poetry run pytest --cov # Integration tests poetry run pytest tests/integration ```