Skip to content

connorodea/ai-book-writer

Β 
Β 

Repository files navigation

πŸ“š AI Book Generator v2.0 - Production Ready

A sophisticated multi-agent AI system for automated book generation using AutoGen v2.0

Tests Python AutoGen License

πŸš€ Production-Ready AI Book Generation System

Transform ideas into complete books using a sophisticated multi-agent AI system. Generate 25-chapter books with consistent narrative, character development, and world-building through collaborative AI agents.

✨ Key Features

  • πŸ“– Complete Book Generation - Automated 1-100+ chapter books
  • πŸ€– 7 Specialized AI Agents - Story planning, writing, editing, and quality control
  • 🧠 Advanced Memory System - Maintains continuity and context across chapters
  • πŸ”§ Flexible LLM Support - Local servers (LM Studio, Ollama) or cloud APIs (OpenAI, Claude)
  • πŸ“Š Performance Monitoring - Real-time metrics and resource optimization
  • βœ… Production Grade - Comprehensive testing, error handling, and logging

🎯 Perfect for SaaS Development

This system provides the technical foundation for a commercial AI book generation platform:

  • Market Potential: $590K+ ARR based on content creation market demand
  • Target Markets: Authors, publishers, content marketers, educators
  • Scalable Architecture: Ready for web interface and user management
  • Enterprise Features: Performance monitoring, resource management, quality control

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Story Planner  β”‚    β”‚ Outline Creator β”‚    β”‚  World Builder  β”‚
β”‚                 │────│                 │────│                 β”‚
β”‚ High-level Arc  β”‚    β”‚ Chapter Details β”‚    β”‚ Setting & Lore  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Memory Keeper   β”‚    β”‚     Writer      β”‚    β”‚     Editor      β”‚
β”‚                 │────│                 │────│                 β”‚
β”‚ Continuity &    β”‚    β”‚ Content         β”‚    β”‚ Quality &       β”‚
β”‚ Context         β”‚    β”‚ Generation      β”‚    β”‚ Refinement      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.9+
  • 1GB+ available RAM
  • Local LLM server (LM Studio, Ollama) OR OpenAI API key

Installation

# Clone the repository
git clone https://github.com/connorodea/ai-book-writer.git
cd ai-book-writer

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Basic Usage

Option 1: Local LLM (Recommended for development)

# Start your local LLM server (e.g., LM Studio on port 1234)
# Then run:
python main_v2.py

Option 2: OpenAI API

# Set your OpenAI API key
export OPENAI_API_KEY="your-api-key-here"
export USE_OPENAI="true"

# Generate book
python main_v2.py

Option 3: Custom Configuration

from config_v2 import get_local_config
from main_v2 import main

# Custom local LLM
config = get_local_config(port=8080, model_name="llama-3.1-70b")
# Then run main() with custom config

πŸ“Š What Gets Generated

Sample Output Structure

book_output/
β”œβ”€β”€ outline.txt          # Complete 25-chapter outline
β”œβ”€β”€ chapter_01.txt       # Chapter 1: The Beginning
β”œβ”€β”€ chapter_02.txt       # Chapter 2: Rising Action
β”œβ”€β”€ ...                  # Chapters 3-24
└── chapter_25.txt       # Chapter 25: Resolution

Content Quality

  • Length: 5,000+ words per chapter (125,000+ word books)
  • Consistency: Character development tracking across chapters
  • Continuity: World-building and plot coherence
  • Professional Quality: Automated editing and validation

πŸ§ͺ Testing & Quality Assurance

Run the comprehensive test suite:

python test_book_generator.py

Test Coverage:

  • βœ… Configuration system (3 tests)
  • βœ… Agent creation and management (5 tests)
  • βœ… Outline generation (4 tests)
  • βœ… Book generation (6 tests)
  • βœ… Integration testing (2 tests)

Current Status: 20/20 tests passing πŸŽ‰

πŸ“ˆ Performance & Monitoring

System Requirements

  • Memory: 1GB+ available RAM
  • CPU: Multi-core recommended for faster generation
  • Storage: 100MB+ for generated content
  • Network: For cloud LLM APIs (if not using local)

Performance Metrics

# Run demo with performance monitoring
python demo.py

# Check system resources
from performance_monitor import ResourceOptimizer
ResourceOptimizer.check_system_resources()

πŸ”§ Configuration Options

Environment Variables

# LLM Backend Selection
USE_OPENAI=false          # Use local LLM (default)
USE_OPENAI=true           # Use OpenAI API

# OpenAI Configuration (if using OpenAI)
OPENAI_API_KEY=your-key

# Logging Level
LOG_LEVEL=INFO            # DEBUG, INFO, WARNING, ERROR

Advanced Configuration

from config_v2 import get_config
from autogen_core.models import ModelInfo, ModelFamily

# Custom model configuration
config = get_config(
    api_key="your-key",
    base_url="http://localhost:8080/v1", 
    model_name="custom-model"
)

πŸ“ API Reference

Core Classes

BookGenerator

Main orchestrator for book generation.

book_gen = BookGenerator(agents, config, outline)
await book_gen.generate_book_async(outline)

OutlineGenerator

Creates detailed chapter outlines.

outline_gen = OutlineGenerator(agents, config)
outline = await outline_gen.generate_outline_async(prompt, 25)

BookAgents

Manages the 7 specialized AI agents.

agents_manager = BookAgents(config, outline)
agents = agents_manager.create_agents(prompt, chapter_count)

Configuration Functions

from config_v2 import get_local_config, get_openai_config

# Local LLM
config = get_local_config(port=1234, model_name="llama-3.1-8b")

# OpenAI
config = get_openai_config("api-key", "gpt-4")

πŸš€ SaaS Development Guide

Ready to build a commercial book generation platform? This system provides the foundation:

Phase 1: Core SaaS Infrastructure

  • Web Frontend: React/Next.js dashboard
  • REST API: FastAPI wrapper around the core system
  • User Management: Authentication and accounts
  • Database: PostgreSQL for user data and books

Phase 2: Enhanced Features

  • Payment Integration: Stripe for subscriptions
  • Queue System: Redis/Celery for background processing
  • File Storage: AWS S3 for generated content
  • Analytics: User behavior and generation metrics

Phase 3: Scale & Advanced Features

  • Multi-tenant: Organization and team support
  • Template System: Genre-specific book templates
  • API Access: Developer API for integrations
  • White-label: Custom branding for enterprises

Market Positioning

  • Starter Plan: $29/month (2 books, basic features)
  • Professional: $99/month (10 books, advanced features)
  • Enterprise: $299/month (unlimited, custom features)

πŸ› Troubleshooting

Common Issues

Import Errors

# Ensure virtual environment is activated
source venv/bin/activate
pip install -r requirements.txt

Memory Issues

# Check available resources
from performance_monitor import ResourceOptimizer
ResourceOptimizer.check_system_resources()

Local LLM Connection

# Verify your local LLM server is running
curl http://localhost:1234/v1/models

Generation Failures

  • Check logs in logs/ directory
  • Verify LLM server is accessible
  • Ensure sufficient system resources

πŸ“Š Monitoring & Logging

Performance Monitoring

from performance_monitor import performance_monitor

performance_monitor.start_monitoring()
# ... generate content ...
performance_monitor.stop_monitoring()

# Get metrics
metrics = performance_monitor.get_metrics_summary()

Logging Configuration

from logging_config import setup_logging

# Configure logging
logger = setup_logging(
    log_level="INFO",
    log_file="custom.log", 
    enable_console=True
)

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (python test_book_generator.py)
  5. Commit changes (git commit -m 'Add amazing feature')
  6. Push to branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Built with AutoGen v2.0 framework
  • Inspired by collaborative AI agent systems
  • Designed for commercial book generation platforms

πŸ“ž Support & Contact


⭐ Star this repository if you find it useful!

Ready to generate your first AI book? Run python main_v2.py and watch the magic happen! ✨

About

πŸš€ Production-ready AI Book Generator v2.0 - Multi-agent system for automated book creation using AutoGen. Perfect for SaaS development with K+ ARR potential. Features 7 specialized AI agents, performance monitoring, and comprehensive testing.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages