--- title: "AI Novelist RAG" emoji: "πŸ“š" colorFrom: "indigo" colorTo: "purple" sdk: docker sdk_version: 28.0.4 python_version: 3.10.16 app_port: 7860 accelerator: cpu # gpu when local, be online in future --- # AI Novelist RAG - Long-Form Story Generation with Memory This is a dedicated AI system for generating long-form novels with coherent logic, consistent world-building, and thematic integrity, solving common LLMs issues like incoherence, self-contradiction, and theme drift. This project combines Langchain, Retrieval-Augmented Generation (RAG), FAISS, FastAPI, and Gradio, along with OpenAI or local quantized models (e.g., LLaMA). It allows the AI to extract key information and context from its own outputs and store them in a vector database to β€œremember” what it’s writtenβ€”resulting in more logical and immersive storytelling. This system is designed as both a technical practice and a creative tool. ## Key Features - High-quality novel generation (via OpenAI APIs or local LLMs) - Automatic information extraction (currently via BERT-based summary model) - Long-context memory (via FAISS vector store) - Context-aware coherent prompt (via RAG-like context enhancement) - Web-based UI (via Gradio) - Experimental consistency scoring (planned to use long-context metrics) ## Project Structure ``` ai-novelist-rag/ β”œβ”€β”€ app/ β”‚ β”œβ”€β”€ main.py # FastAPI + Gradio mount point β”‚ β”œβ”€β”€ apis/ # API endpoints for generation, editing, benchmarks β”‚ β”œβ”€β”€ front_end/ # Gradio-based UI β”‚ β”œβ”€β”€ managers/ # Managers and chains for chapter, summary, and vector memory β”‚ β”œβ”€β”€ models/ # Model loading and wrapper logic β”‚ β”œβ”€β”€ tests/ # (Not showed here) Jupyter notebooks for quick testing β”‚ └── utils/ # General utilities β”‚ β”œβ”€β”€ data/ # (Not showed here) Local store for texts, summaries, vector DB β”œβ”€β”€ docker/ # Dockerfile and config for deployment β”œβ”€β”€ scripts/ β”‚ β”œβ”€β”€ setup.sh # Install dependencies β”‚ └── start.sh # Start the app program β”‚ β”œβ”€β”€ requirements.txt β”œβ”€β”€ README.md β”œβ”€β”€ Dockerfile └── .gitignore ``` ## Getting Started 1. Install dependencies: ```bash bash scripts/setup.sh ``` 2. Start the app program: ```bash bash scripts/start.sh ``` Default setup: - Uses gpt-4o-mini (via OpenAI API) for novel generation - Uses bart-large-cnn for chapter summarization - Configurable in config.py (coming soon) Requires your own OpenAI API key ## Coming Soon - Chinese-style writing support - Multiple books/novels within the same workspace - Streaming generation responses to frontend - Benchmark consistency improvement with and without memory - Deployment to Azure ## Contributing This project is still under active development, Star, Fork, and PRs are welcome!