⏱️ Estimated reading time: 15 minutes

Introduction

With the advancement of AI technology, it’s now possible to automatically generate long-form novels using artificial intelligence. The AI_NovelGenerator is a powerful tool that leverages OpenAI API and vector search technology to create consistent, multi-chapter novels automatically.

This tutorial will guide you through the installation, setup, and usage of the AI Novel Generator, step by step.

What is AI Novel Generator?

The AI Novel Generator is a sophisticated tool with the following features:

  • Automated Long-Form Generation: Creates novels with 100+ chapters automatically
  • Consistency Maintenance: Ensures character and setting consistency through vector search
  • GUI Interface: User-friendly graphical interface for easy operation
  • Multi-Model Support: Compatible with OpenAI, Claude, Ollama, and other AI models

Installation and Setup

1. Clone the Project

git clone https://github.com/YILING0013/AI_NovelGenerator
cd AI_NovelGenerator

2. Install Dependencies

pip install -r requirements.txt

3. Create Configuration File

Create a config.json file in the project root with the following configuration:

{
    "api_key": "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "base_url": "https://api.openai.com/v1",
    "interface_format": "OpenAI",
    "model_name": "gpt-4o-mini",
    "temperature": 0.7,
    "max_tokens": 4096,
    "embedding_api_key": "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "embedding_interface_format": "OpenAI",
    "embedding_url": "https://api.openai.com/v1",
    "embedding_model_name": "text-embedding-ada-002",
    "embedding_retrieval_k": 4,
    "topic": "A story about human resistance in a future world dominated by AI",
    "genre": "Science Fiction",
    "num_chapters": 50,
    "word_number": 3000,
    "filepath": "/path/to/your/novel/output"
}

Detailed Configuration Guide

API Key Setup

  1. OpenAI API Key: Obtain your API key from the OpenAI Platform.
  2. Base URL: Use https://api.openai.com/v1 for OpenAI services.
  3. Model Selection: Choose from GPT-4, GPT-3.5-turbo, or other available models.

Novel Settings

  • topic: Core theme and setting of your novel
  • genre: Novel genre (Science Fiction, Fantasy, Romance, etc.)
  • num_chapters: Total number of chapters
  • word_number: Target word count per chapter

Step-by-Step Usage Guide

Step 1: Basic Configuration

Run the program to launch the GUI:

python main.py

In the GUI, enter the following information:

  • API Key and Base URL
  • Model name
  • Temperature (creativity level)
  • Novel topic and genre
  • Number of chapters and words per chapter
  • Output file path

Step 2: Generate Novel Settings

Click “Step1. Generate Settings” to create the Novel_setting.txt file, which includes:

  • World-building elements
  • Main character information
  • Story arcs
  • Important setting details

Step 3: Generate Table of Contents

Click “Step2. Generate Table of Contents” to create the Novel_directory.txt file with chapter titles and brief descriptions.

Step 4: Generate Chapters

Click “Step3. Generate Chapter Draft” to create specific chapters:

  1. Enter chapter number
  2. Add additional instructions for the chapter (optional)
  3. Click generate

The system automatically:

  • Analyzes previous chapters using vector search
  • Ensures character and setting consistency
  • Generates chapter outline (outline_X.txt) and content (chapter_X.txt)

Step 5: Finalize Chapter

Click “Step4. Finalize Current Chapter” to:

  • Update global summary (global_summary.txt)
  • Update character states (character_state.txt)
  • Update vector search database
  • Update plot arcs (plot_arcs.txt)

Step 6: Consistency Check (Optional)

Click “Consistency Check” to verify the latest chapter for any contradictions in character behavior or settings.

Advanced Configuration

Vector Search Setup

Vector search is crucial for maintaining novel consistency:

{
    "embedding_model_name": "text-embedding-ada-002",
    "embedding_retrieval_k": 4
}

Using Local Models (Ollama)

To use Ollama locally:

# Start Ollama service
ollama serve

# Download embedding model
ollama pull nomic-embed-text

Update your configuration file:

{
    "embedding_interface_format": "Ollama",
    "embedding_url": "http://localhost:11434",
    "embedding_model_name": "nomic-embed-text"
}

Troubleshooting

Common Errors

  1. “Expecting value: line 1 column 1 (char 0)”
    • Occurs when API response is incorrect
    • Verify API key and URL
  2. “HTTP/1.1 504 Gateway Timeout”
    • API server connection issues
    • Check network connectivity
  3. Vector Search Errors
    • Delete vectorstore directory and restart
    • Recommended when changing embedding models

Tips and Best Practices

Effective Novel Generation

  1. Clear Topic Setting: Set specific and clear topics for your novel.
  2. Appropriate Chapter Count: Too many chapters can make consistency maintenance difficult.
  3. Regular Review: Regularly review and edit generated content.

Performance Optimization

  1. Optimal Temperature: 0.7-0.8 provides a good balance between creativity and consistency.
  2. Vector Search Settings: Adjust embedding_retrieval_k to retrieve more relevant information.

Conclusion

The AI Novel Generator opens new possibilities for writers. While it doesn’t create perfect novels automatically, it provides significant assistance in idea generation and initial draft creation.

Use this tool to create your unique novels and experience the intersection of AI and human creativity.

References


💡 Tip: Start with a shorter novel (10-20 chapters) for your first attempt to familiarize yourself with the tool’s operation.