This project generates a fantasy book using Large Language Models (LLMs) from the LangChain community. The process involves generating story ideas, creating a synopsis, structuring chapters, and drafting and verifying chapter content.
The repository contains the following key files and folders:
- main.py: The main script that orchestrates the story generation process.
- prompts.py: Contains the prompt templates for various phases (idea generation, synopsis, quality verification, etc.).
- generated/: When the
main.pyscript is executed and a synopsis is approved, this folder is created (if it doesn't already exist) with:- A subdirectory named after the book title (e.g.,
Echoes of the Veil), containing:structure.md: A file outlining the detailed book structure and chapter breakdown.- One Markdown file per chapter (e.g.,
1.md,2.md, etc.) with the final polished chapter content.
- A subdirectory named after the book title (e.g.,
- README.md: This documentation file.
- requirements.txt: Lists the required dependencies for the project.
- LICENSE: The project’s license file.
- Python 3.13.2 or higher
- LangChain library
- Ollama models
-
Clone the repository:
git clone https://github.com/yourusername/fantasy-book-generator.git cd fantasy-book-generator -
Install the required dependencies:
pip install -r requirements.txt
-
Install Ollama and the required models:
- Download and install Ollama following their official instructions.
- Ensure the following models are installed and available:
- deepseek-r1:1.5b
- gemma3:1b
- mistral:latest
- Start the Ollama models locally on
http://localhost:11434.
To generate a fantasy book, run the main.py script:
sh python main.py
The script will go through the following phases:
- Generating Story Ideas: Creates five detailed fantasy story ideas.
- Generating Synopsis: Composes a detailed synopsis based on the generated ideas.
- Quality Verification: Analyzes the synopsis for consistency, completeness, plot potential, and originality.
- Final Approval Check: Checks if the synopsis meets all the required criteria.
- Structuring Chapters: Generates a detailed chapter-by-chapter structure for the book.
- Chapter Generation and Verification: Drafts and verifies each chapter based on the structure.
- Final Chapter Generation: Produces a polished final version of each chapter.
Generated content will be saved in the generated/ directory under a subfolder corresponding to the book title.
The prompts used for generating and verifying content are defined in prompts.py. They include:
IDEA_GENERATION_PROMPTSTORY_SYNOPSIS_PROMPTQUALITY_VERIFICATION_PROMPTFINAL_APPROVAL_CHECK_PROMPTBOOK_STRUCTURE_PROMPTCHAPTER_DRAFT_PROMPTCHAPTER_VERIFICATION_PROMPTFINAL_CHAPTER_GENERATION_PROMPT
This project is licensed under the MIT License. See the LICENSE file for details.
Ensure the following LLMs are pulled and available from Ollama:
deepseek-r1:1.5bfor creative idea generationgemma3:1bfor quality verification and structure generationmistral:latestfor chapter generation