nanfangwuyu21 commited on
Commit
1682dce
·
1 Parent(s): 687bbdc

Create new README.md

Browse files
README.md CHANGED
@@ -1,147 +1,74 @@
1
- # 🧠 AI Novelist RAG
2
 
3
- A dedicated AI system for long-form novel generation, designed to tackle common issues like **incoherent logic**, **self-contradiction**, and **theme drift** in LLM-generated narratives.
4
 
5
- This project integrates **Langchain + RAG + FastAPI + Local Quantized Models (e.g., Qwen)** to enable the AI to **extract key narrative elements** from its own outputs and store them in a memory-enhancing vector database (FAISS), effectively boosting logic retention and narrative consistency.
6
 
7
- ---
8
 
9
- ## 🧩 Core Idea
10
 
11
- > **Let the AI "remember" what it writes, to keep stories logically consistent.**
 
 
 
 
 
12
 
13
- - High-quality novel generation via Qwen
14
- - ✅ Automatic extraction of key narrative settings (characters, themes, backgrounds)
15
- - ✅ Vector memory with FAISS for context recall
16
- - ✅ Retrieval-augmented writing with self-referencing history
17
- - ✅ Optional consistency scoring using CoT-style benchmarks
18
-
19
- ---
20
-
21
- ## 📂 Project Structure
22
 
23
  ```
24
  ai-novelist-rag/
25
  ├── app/
26
- │ ├── main.py
27
- │ ├── config.py
28
- │ ├── apis/
29
- ├── generator.py
30
- ├── extractor.py
31
- ├── memory.py
32
- └── benchmark.py
33
- ├── models/
34
- │ │ ├── model.py
35
- │ │ └── faiss_index.py
36
- │ ├── chains/
37
- │ │ ├── rag_chain.py
38
- │ │ └── memory_insert_chain.py
39
- │ └── utils/
40
- │ ├── logger.py
41
- │ ├── text_processing.py
42
- │ └── utils.py
43
- ├── data/
44
- │ ├── memory_store.faiss
45
- │ └── samples/
46
- │ ├── raws/
47
- │ └── processed/
48
- ├── docker/
49
- │ ├── Dockerfile
50
- │ └── docker-compose.yml
51
  ├── scripts/
52
- └── launch_local.sh
53
- ├── tests/
 
54
  ├── requirements.txt
55
  ├── README.md
56
  └── .gitignore
57
  ```
58
 
59
- ---
60
 
61
- ## 🚀 Quick Start
62
 
63
  ```bash
64
- bash scripts/launch_local.sh
65
  ```
66
 
67
- Default: Local quantized Qwen model (configurable via `config.py`).
68
-
69
- ---
70
-
71
- ## 📌 Tech Stack
72
-
73
- - 🤖 Qwen quantized (INT4 / bfloat16)
74
- - 🧱 Langchain pipeline management
75
- - 🔍 FAISS for vector search
76
- - 🔁 Retrieval-Augmented Generation (RAG)
77
- - 🛠️ FastAPI for backend serving
78
- - 🐳 Docker/docker-compose (optional deployment)
79
-
80
- ---
81
-
82
- ## 📌 TODO
83
-
84
- - [ ] Interactive multi-turn topic-driven generation
85
- - [ ] CoT-style logic scoring feedback loop
86
- - [ ] Azure / Hugging Face Spaces deployment
87
- - [ ] Unit test integration
88
-
89
- ---
90
-
91
- ## 🧠 Suitable For
92
-
93
- - AI + Literature applications
94
- - Multimodal + long-context logic reasoning
95
- - Langchain + RAG stack practice
96
- - Technical portfolio for interviews
97
-
98
- ---
99
-
100
- # 🧠 AI Novelist RAG(中文)
101
-
102
- 一个专为“小说生成”设计的 AI 系统,致力于解决大语言模型在长文本生成中常见的 **逻辑性弱**、**前后矛盾**、**主题偏移** 等问题。
103
-
104
- 本项目结合 **Langchain + RAG + FastAPI + 本地量化模型(如 Qwen)**,实现 AI 在小说生成过程中自动抽取关键设定,并写入向量记忆库,从而增强模型的“逻辑一致性”和“记忆保持”。
105
-
106
- ## 🧩 核心思想
107
-
108
- > **AI 自动记忆自己写过的内容,保持小说逻辑统一。**
109
-
110
- ## 📂 项目结构
111
-
112
- (同上,略)
113
-
114
- ## 🚀 快速启动
115
 
116
  ```bash
117
  bash scripts/launch_local.sh
118
  ```
119
 
120
- 默认使用本地 Qwen 模型(量化版本),配置可在 `config.py` 中修改。
121
-
122
- ## 📌 依赖技术栈
123
-
124
- - 🤖 Qwen 本地量化模型(INT4 / bfloat16)
125
- - 🧱 Langchain 流程构建
126
- - 🔍 FAISS 向量数据库
127
- - 🔁 Retrieval-Augmented Generation(RAG)
128
- - 🛠️ FastAPI 后端接口
129
- - 🐳 Docker / docker-compose 部署(可选)
130
 
131
- ## 📌 TODO(下一阶段)
 
 
132
 
133
- - [ ] 添加多轮生成支持
134
- - [ ] 实现逻辑评分反馈机制
135
- - [ ] 云端部署版本(Azure / Hugging Face Spaces)
136
- - [ ] 单元测试支持
137
 
138
- ## 🧠 项目适用于
139
 
140
- - AI + 文学创作方向
141
- - 多模态 + 长上下文推理实验
142
- - Langchain + RAG 训练项目
143
- - 技术型面试展示
 
144
 
145
- ---
146
 
147
- 欢迎 Star & Fork,开发中 🚧
 
1
+ # AI Novelist RAG · Long-Form Story Generation with Memory
2
 
3
+ 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.
4
 
5
+ 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.
6
 
7
+ This system is designed as both a technical practice and a creative tool.
8
 
9
+ ## Key Features
10
 
11
+ - High-quality novel generation (via OpenAI APIs or local LLMs)
12
+ - Automatic information extraction (currently via BERT-based summary model)
13
+ - Long-context memory (via FAISS vector store)
14
+ - Context-aware coherent prompt (via RAG-like context enhancement)
15
+ - Web-based UI (via Gradio)
16
+ - Experimental consistency scoring (planned to use long-context metrics)
17
 
18
+ ## Project Structure
 
 
 
 
 
 
 
 
19
 
20
  ```
21
  ai-novelist-rag/
22
  ├── app/
23
+ │ ├── main.py # FastAPI + Gradio mount point
24
+ │ ├── apis/ # API endpoints for generation, editing, benchmarks
25
+ │ ├── front_end/ # Gradio-based UI
26
+ │ ├── managers/ # Managers and chains for chapter, summary, and vector memory
27
+ │ ├── models/ # Model loading and wrapper logic
28
+ │ ├── tests/ # Jupyter notebooks for quick testing
29
+ │ └── utils/ # General utilities
30
+
31
+ ├── data/ # (Not showed here) Local store for texts, summaries, vector DB
32
+ ├── docker/ # Dockerfile and config for deployment
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ├── scripts/
34
+ ├── setup.sh # Install dependencies
35
+ │ └── launch_local.sh # Launch the app locally
36
+
37
  ├── requirements.txt
38
  ├── README.md
39
  └── .gitignore
40
  ```
41
 
42
+ ## Getting Started
43
 
44
+ 1. Install dependencies:
45
 
46
  ```bash
47
+ bash scripts/setup.sh
48
  ```
49
 
50
+ 2. Launch the app locally:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  ```bash
53
  bash scripts/launch_local.sh
54
  ```
55
 
56
+ Default setup:
 
 
 
 
 
 
 
 
 
57
 
58
+ - Uses gpt-4o-mini (via OpenAI API) for novel generation
59
+ - Uses bart-large-cnn for chapter summarization
60
+ - Configurable in config.py (coming soon)
61
 
62
+ Requires your own OpenAI API key
 
 
 
63
 
64
+ ## Coming Soon
65
 
66
+ - Chinese-style writing support
67
+ - Multiple books/novels within the same workspace
68
+ - Streaming generation responses to frontend
69
+ - Benchmark consistency improvement with and without memory
70
+ - Deployment to Azure
71
 
72
+ ## Contributing
73
 
74
+ This project is still under active development, Star, Fork, and PRs are welcome!
docker_run.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ docker build -t ai-novelist .
4
+
5
+ docker run -p 8000:8000 -p 7860:7860 ai-novelist
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
- # model
2
  # torch>=2.0.0
3
  transformers>=4.36.0
 
4
  pillow>=9.0.0
5
  numpy
6
  bitsandbytes
@@ -12,14 +13,16 @@ faiss-cpu
12
  langchain
13
  langchain-community
14
  openai
15
-
16
- # openai
17
  einops
18
 
19
-
20
- # fastapipip
21
  fastapi
22
  uvicorn
23
 
 
 
 
 
24
  #jupyter
25
  ipykernel
 
1
+ # AI
2
  # torch>=2.0.0
3
  transformers>=4.36.0
4
+ huggingface_hub
5
  pillow>=9.0.0
6
  numpy
7
  bitsandbytes
 
13
  langchain
14
  langchain-community
15
  openai
16
+ pydantic
 
17
  einops
18
 
19
+ # backend
 
20
  fastapi
21
  uvicorn
22
 
23
+ # frontend
24
+ gradio
25
+ requests
26
+
27
  #jupyter
28
  ipykernel
scripts/launch_local.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ uvicorn app.main:app
setup.sh → scripts/setup.sh RENAMED
File without changes