fangfufu/LLM-book-generator:基于 llama.cpp 的整本书自动生成工具
fangfufu/LLM-book-generator
fangfufu/LLM-book-generator 是一个 Python 命令行工具,通过 llama.cpp 的 llama-server 调用 LLM,从选题到成稿自动生成整本书,包括书名、章节大纲、正文、前后附文和营销材料。它支持 LaTeX 数学公式转图片、可自定义样式的 DOCX 排版、LLM 响应缓存,并通过 config.yaml 配置,采用 GPLv3 许可。
LLM Book Generator is a powerful Python-based command-line tool that automates the creation of entire books, from initial concept to a fully formatted DOCX manuscript. It leverages Large Language Models (LLMs) via llama.cpp to generate diverse content, including titles, chapter outlines, detailed section text, front and back matter, and even marketing materials.
Features
- llama.cpp Support: Seamlessly integrates with llama.cpp server (
llama-server). - Comprehensive Content Generation: Creates everything from titles and chapter outlines to front and back matter.
- LaTeX Math Rendering: Converts LaTeX math expressions into high-quality images.
- Advanced DOCX Styling: Produces professionally formatted DOCX files with customizable styles.
- Intelligent Caching: Caches LLM responses to speed up subsequent runs.
- Flexible Configuration: Uses a
config.yamlfile for easy customization.
Getting Started
Prerequisites
- Python 3.8+
- A LaTeX distribution (e.g., MiKTeX, MacTeX, TeX Live)
- A running llama.cpp server instance (
llama-server).
Installation
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment (Optional): If using Hugging Face tokenizers requiring authentication, create a
.envfile in the project root:HF_TOKEN="YOUR_HUGGING_FACE_TOKEN"
How to Run
-
Configure your book: Edit the
config.yamlfile to define your book's topic, author, style, and other parameters. For a detailed explanation of all the available options, see CONFIG.md. -
Run the script:
python main.py
The generated book and marketing materials will be saved in the directory specified in
config.yaml(default is"output").
Troubleshooting
- LaTeX Math Rendering Issues: Ensure your LaTeX distribution is installed correctly and accessible from your system's PATH.
- API Errors: Ensure that your llama.cpp server is running and accessible (default:
http://localhost:8080). - File Permissions: Make sure the script has write access to the output and cache directories.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue.
License
This project is licensed under GPLv3. See the LICENSE file for details.
来源:GitHub · github.com