Skip to content
项目

关于

基于大模型的AI小说创作系统,支持小说和课程内容的智能生成,包含世界观设定、思维库、任务管理等完整功能。

效率与自动化

这些数字如何统计

实测星标增长

24小时
0
7天
+1
15天
+1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

AI Novelist

A long-form novel writing workbench. Give it a premise; it plans the whole book, keeps a structured story bible so characters and foreshadowing stay consistent across dozens of chapters, writes chapter by chapter, reviews what it wrote, and keeps every version so you can roll back.

v3.0 — rebuilt generation engine. The early "prompt + summary sliding window" design that caused character drift and lost foreshadowing is gone.


Quick start (no API key needed)

python -m pip install -r requirements.txt
python main.py            # -> http://127.0.0.1:5000

The app boots in mock mode: a deterministic local model produces believable outlines, plans, prose, reviews and bible extractions, so the entire pipeline — planning, writing, review, versions, export — is demoable offline.

To use a real model, set an OpenAI-compatible endpoint (DeepSeek / OpenAI / Zhipu / Qwen / Ollama / vLLM all work):

AI_NOVEL_MOCK=0 \
AI_NOVEL_LLM_URL=https://api.deepseek.com/v1 \
AI_NOVEL_MODEL=deepseek-chat \
AI_NOVEL_API_KEY=sk-... \
python main.py

Model profiles and per-purpose routing (plan / write / review / summary / bible / rewrite) are editable under 用量与设置, with automatic fallback down the chain.

What it does

Area Behaviour
Story bible Characters, locations, items, organisations, world rules, relations, timeline events and a foreshadow ledger, all structured in SQLite. Updated incrementally after every chapter with locked-field protection and conflict reporting.
Layered planning Book outline → volume plan → chapter outline → 4-6 beats. Every chapter records the plan revisions it was written against, so a plan edit marks affected chapters stale.
Context assembly Plan chain + relevance-sliced bible + full text of recent chapters + FTS retrieval of older passages, each with its own token budget. Nothing is head/tail truncated.
Structured output JSON mode + strict pydantic schemas + bounded repair retries. No regex guessing.
Review Deterministic checks (beats landing, word count, foreshadow status) plus an LLM consistency/style review that yields a scored, quotable issue list.
Versions Every generation / rewrite / manual save becomes an immutable version with diff and rollback. Failed generations never write placeholder content.
Durable queue Tasks and steps live in the database with leases, heartbeats and restart recovery; a crashed run resumes at the first unfinished step.
Export Per-chapter md / txt / docx, whole-project zip, and read-only share links.
Legacy import Existing works_library/ markdown works can be imported and continue to be read, edited and exported.

What changed in v3

  • Architecture — five layers (api / application / domain / infrastructure / workers); routes.py (715 lines) and services/* were removed.
  • No more worldview truncation — the old _truncate_worldview kept head 2000 + tail 2000 chars and dropped the middle, exactly where character profiles lived. Replaced by relevance-scored bible slicing with an explicit dropped-item report.
  • No more regex JSON — the greedy brace regex is gone; output is validated against pydantic models with a bounded repair pass.
  • No more placeholder files — a failed chapter fails its task with an error code and leaves the chapter untouched.
  • Offline front end — no CDN (marked / chart.js / Google Fonts removed), split into ES modules, light + dark themes, responsive at 1440 / 768 / 390.

Project layout

main.py                 web entry point (hosts the worker thread in private mode)
worker.py               standalone worker process (SaaS shape)
app/
  api/                  /api/v1 blueprints: projects chapters plans bible tasks events ...
  application/          use cases: project, planning, generation, bible, task, import/export
  domain/               pure rules: bible/ planning/ context/ review/ generation/
  infrastructure/       db engine, llm gateway + providers, usage, observability
  models/               SQLAlchemy entities (mirrors ai-docs data model)
  prompts/              prompt registry with schema versions
  workers/              runner, step protocol, recovery
  static/js/            ES modules: api, ui, app shell, views/*
  static/css/app.css    design system (paper palette, serif display type)
tests/                  pytest: API contract, pipeline, queue, bible, planning

API

All business endpoints live under /api/v1. Highlights:

POST /api/v1/projects                        create a work
POST /api/v1/projects/{id}/outline/generate  book plan task
POST /api/v1/projects/{id}/write             write chapters task
GET  /api/v1/chapters/{id}/context           show exactly what the model saw
POST /api/v1/chapters/{id}/versions          save an edit as a new version
POST /api/v1/chapters/{id}/rewrite           targeted rewrite task
GET  /api/v1/projects/{id}/bible             bible summary
POST /api/v1/bible/patches/{id}/apply        apply an extracted patch
GET  /api/v1/tasks?project_id=               task queue
GET  /api/v1/events?project_id=              SSE stream
GET  /api/v1/usage/summary                   tokens & cost
GET  /api/v1/ops/health                      health

Errors are always {"error": {"code": "...", "message": "...", "details": {...}}} with stable codes such as VERSION_CONFLICT, TASK_PROJECT_BUSY, LLM_SCHEMA_INVALID.

Configuration

Env var Default Meaning
AI_NOVEL_MOCK 1 Use the built-in local model (no key, offline)
AI_NOVEL_LLM_URL https://api.openai.com/v1 OpenAI-compatible base URL
AI_NOVEL_MODEL gpt-4o-mini Model id
AI_NOVEL_API_KEY — Key, resolved at the gateway only and never logged
AI_NOVEL_DATA_DIR data SQLite DB + export artifacts
AI_NOVEL_DB_URL — Override with a full SQLAlchemy URL (PostgreSQL)
AI_NOVEL_CONTEXT_BUDGET 12000 Context token budget per chapter
AI_NOVEL_WORKER 1 Run the worker in-process
WORKS_LIBRARY_PATH_OVERRIDE works_library Legacy import source

Backup = copy data/ai_novel.db (plus data/exports/). Legacy works_library/ is read-only import material and no longer written at runtime.

Tests

python -m pytest -q

34 tests cover: the v1 API contract, version/revision conflict handling, the full generation pipeline (plan → prose → review → version → bible patch), context assembly budgets, empty-rewrite rejection, failure paths that must not write placeholders, the durable queue (busy guard, pause/resume/cancel, retry rules, restart recovery, idempotency keys), bible merge locking and relevance slicing, and planning edits.

Known limitations

  • SaaS mode (accounts, tenants, quota) is scaffolded — tenant_id, AuthProvider seam and usage tables exist — but authentication and billing are not implemented.
  • Content moderation is not implemented; upstream provider refusals surface as error codes.
  • Retrieval is SQLite FTS5 keyword based; no embedding index yet.
  • PDF export is not implemented (md / txt / docx / zip only).
  • The mock model writes serviceable Chinese prose but it is a demo stand-in; quality depends on a real model.

License

MIT — see LICENSE.

探索相关项目

加载中…