Infinite Bookshelf 开源:输入主题即可流式生成整本结构化书籍
Sasivarnasarma/infinite-bookshelf
Infinite Bookshelf 是一个开源项目,输入主题后先起草目录供编辑,再逐节流式写完整本书,每节都能看到大纲和前面章节的摘要,避免内容重复。它内置 16 家供应商并支持任意 OpenAI 兼容 API,可为大纲、标题、章节分别选择模型,随时切换,也能用一条备注重写任意章节。
Turn a topic into a complete, structured book, written live by the AI model of your choice.
Bring your own API key · 16 providers and any OpenAI-compatible API · Self-hosted in one container
Try it live at ib.sasivarnasarma.me →
Quick start · Features · How it works · Privacy · Docs
✨ What it is
Type a topic, such as "The history of tea" or "Linear algebra for programmers". Infinite Bookshelf drafts a table of contents, lets you edit it, then writes the book section by section. You watch every word stream in, the way a model writes it.
Each section knows the outline and what earlier sections already covered, so chapters build on each other instead of repeating. You choose the model for every step, can switch it at any time, and can rewrite any section with a note. When the book is done, export it as Markdown, a typeset PDF, or a backup file.
It runs on your API keys, which never leave your browser except to make a request, and your books never leave your browser at all.
🚀 Quick start
Tip
Just want to try it? Open ib.sasivarnasarma.me and add a key from any provider: nothing to install. Your key and book text pass through that server for each request (never stored or logged); run your own copy if you'd rather they didn't.
🐳 Docker (recommended)
git clone https://github.com/Sasivarnasarma/infinite-bookshelf.git
cd infinite-bookshelf
docker compose up -dOpen http://localhost:9752.
💻 From source
Needs uv, Node.js 22+ and pnpm.
pnpm bootstrap # install everything cp .env.example .env # optional settings pnpm dev # API on :8000, web app on :5173
Open http://localhost:5173.
📦 Without Docker
To run the finished app on a server without Docker, build it once and start it:
pnpm bootstrap # install everything pnpm build # build the web app pnpm start # serve the app and the API → http://localhost:9752
One process serves everything on port 9752, like the container. See Self-hosting → Without Docker for keeping it running with systemd.
Then go to Settings → Providers & models, add a provider, and paste your API key. Google Gemini has a generous free tier, and Ollama runs models on your own machine with no key at all.
Tip
On GitHub Codespaces, or anywhere the container can't look up domain names, run
docker compose up -d infinite-bookshelf-host instead. It uses the host's network.
See Self-hosting.
🌟 Features
📝 Write
|
🤖 Models
|
🪄 Refine
|
📦 Export and more
|
Supported providers
| Kind | Providers |
|---|---|
| Model makers | OpenAI · Anthropic Claude · Google Gemini · xAI Grok · DeepSeek · Mistral AI · Moonshot Kimi · Alibaba Qwen · Z.ai GLM |
| Gateways and fast inference | OpenRouter · Groq · Together AI · Fireworks AI · Cerebras |
| On your own machine | Ollama · LM Studio |
| Anything else | Any OpenAI-compatible API, added with its base URL (vLLM, LiteLLM, llama.cpp server…) |
Free tiers: Google Gemini, Groq and Cerebras. Ollama and LM Studio need no key.
🔍 How it works
flowchart LR
subgraph Browser["🌐 Your browser"]
UI["Web app<br/>(React)"]
Keys[("API keys<br/>localStorage")]
Books[("Books<br/>IndexedDB")]
end
subgraph Server["🖥️ Infinite Bookshelf server (stateless)"]
API["FastAPI<br/>prompts · streaming · PDF"]
end
Provider["☁️ AI provider<br/>(OpenAI, Gemini, Ollama…)"]
Keys -. key, per request .-> UI
UI <--> Books
UI -- "topic, outline, book so far + key" --> API
API -- "model request" --> Provider
Provider -- "tokens" --> API
API -- "Server-Sent Events" --> UI
Loading
- Outline. The server asks your outline model for a table of contents and your title model for a title, streaming both back.
- Review. You edit the outline in the browser, or skip review and start writing at once.
- Write. The browser asks for one section at a time, sending the outline and the sections written so far. The server builds the prompt and streams the model's words back. Each finished section is saved in your browser straight away.
- Export. Markdown and backups are made in the browser; the server typesets PDFs.
The server stores nothing: no database, no accounts, no sessions. Read the architecture guide for the details.
🔒 Your data stays yours
| Where it lives | What the server does | |
|---|---|---|
| API keys | Your browser (or only this tab) | Uses the key for one request, then forgets it. Never stored or logged. |
| Books | Your browser's IndexedDB | Receives the outline and text needed for each request, then forgets them. |
| Settings | Your browser | Nothing. |
- The page loads no third-party scripts, fonts or trackers, under a strict Content Security Policy.
- Turn off Remember my keys and they're kept only until you close the tab.
- Back books up from Settings → Your data; they exist nowhere else.
Important
Running a server for other people? Read Running a public instance first. The default Docker Compose file is set up for a private server.
📚 Documentation
| Guide | What's in it |
|---|---|
| Self-hosting | Docker, configuration, local models, reverse proxies, public instances, troubleshooting |
| Architecture | How the browser and server work together, streaming, prompts, PDF export, security |
| API reference | Endpoints, request bodies, streamed events, error codes |
| Web app | The web app's commands, IB_API_URL, and conventions |
| Contributing | Development setup, checks, tests and commit style |
| Security policy | How to report a vulnerability, and what's protected |
| Changelog | What changed in each release |
📁 Project layout
infinite-bookshelf/
├── api/ Python API: FastAPI, uv, pytest
│ ├── src/infinite_bookshelf/
│ │ ├── engine/ book-writing logic: prompts, providers, PDF (no web code)
│ │ └── server/ HTTP layer: routes, streaming, security, settings
│ └── tests/
├── web/ Web app: React 19, TypeScript, Vite, Tailwind CSS, Vitest
│ └── src/ pages, components, and lib/ (the writing loop, storage, settings)
├── docs/ Architecture and self-hosting guides
├── Dockerfile One image: the API serving the built web app
├── docker-compose.yml Self-hosting on port 9752
└── .env.example Every setting, with its default
| Command | What it does |
|---|---|
pnpm bootstrap |
Install the web and API dependencies |
pnpm dev |
Run the API (:8000) and web app (:5173), both reloading on changes |
pnpm check |
Everything CI runs: formatting, lint, typecheck and all tests |
pnpm test |
Web tests (Vitest), then API tests (pytest) |
pnpm format |
Format the web app and docs (Prettier) and the API (Ruff) |
pnpm build |
Production build of the web app |
pnpm start |
Serve the built web app and the API on :9752, without Docker |
🤝 Contributing
Issues and pull requests are welcome. Start with CONTRIBUTING.md; please report security problems privately, as described in SECURITY.md.
💛 Credits
Infinite Bookshelf began as the original Infinite Bookshelf by Benjamin Klieger, and this project is built on that idea.
Provider names and logos are trademarks of their owners, shown only to indicate compatibility.
📄 Licence
Distributed under the MIT License
来源:GitHub · github.com