π Fiction AI - AI-Powered Novel Writing Assistant
Let AI be your creative partner, not your replacement
π Inspiration
As a web novel enthusiast and developer, I deeply understand the pain points of long-form fiction writing:
$$ \text{Writing Efficiency} = \frac{\text{Creative Output}}{\text{Repetitive Tasks} + \text{Context Management} + \text{Setting Maintenance}} $$
In traditional writing, authors spend enormous time on:
- Memory Management: Who remembers that side character's name from Chapter 3 in a 500,000-word novel?
- Setting Consistency: Did the protagonist's eye color just change in Chapter 10?
- Plot Continuity: Foreshadowing planted but forgotten, storylines broken and disconnected
My inspiration came from a simple idea: AI shouldn't replace authorsβit should be a "tireless assistant"βremembering all settings, managing all characters, tracking all plot lines, so authors can focus on what matters most: the creative work itself.
π What I Learned
1. AI Agent Engineering in Practice
This project gave me deep insights into the power of Function Calling. Using Spring AI 1.0.2, I implemented 16+ specialized tools:
// Tool definition example - Chapter content search
@Tool(name = "SearchChapterContent",
description = "Search keywords in chapter content, supports single chapter or global search")
public SearchResult search(
@ToolParam("Novel ID") Long novelId,
@ToolParam("Search keyword") String keyword
) { ... }
AI is no longer a simple "Q&A machine"βit can now:
- Read chapter content and character settings
- Create and modify chapters
- Apply Diff patches for precise editing
- Generate character relationship diagrams and plot timelines
2. Multi-Model Compatibility Challenges
Supporting OpenAI, Claude, and Gemini taught me:
$$ \text{Compatibility Complexity} \propto \sum_{i=1}^{n} \text{API Differences}_i \times \text{Response Formats}_i $$
Each model has subtle differences in Tool Calling formats and streaming response handling. Designing a unified abstraction layer was crucial.
3. Real-Time Collaboration Depth
The WebSocket + SSE hybrid architecture revealed the complexity of real-time systems:
- SSE for AI streaming output
- WebSocket for multi-device synchronization
- Redis for session state management
π§ How I Built It
Architecture Design
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend Layer β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
β β Vue 3 β β TipTap β β Mermaid/G6 β β
β β + Vite β β Editor β β Chart Rendering β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Backend Layer β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Spring Boot 3.3.5 β β
β β βββββββββββββ βββββββββββββ βββββββββββββββββ β β
β β β Spring AI β β WebSocket β β Sa-Token Auth β β β
β β β 1.0.2 β β + SSE β β β β β
β β βββββββββββββ βββββββββββββ βββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data Layer β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
β β MySQL β β Redis β β Dify Workflow β β
β β 8.0 β β Cache β β (One-Click Write) β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Core Modules
- AI Chat Service - Unified multi-model conversation service
- Tools System - 16+ specialized writing tools
- Novel Management - Novel, chapter, character, and outline management
- Chart Generation - Mermaid charts (character relationships, plot lines)
- Prompt Market - Prompt marketplace for sharing creative templates
π§ Challenges I Faced
Challenge 1: Limited Context Window
Long novels can reach hundreds of thousands of words, but AI context windows are limited:
$$ \text{Token Limit}: \quad \text{Context} \leq 128K \ll \text{Total Novel Length} $$
Solution:
- Chapter summary system: Generate structured JSON summaries for each chapter
- Smart context building: Load only relevant chapters and character settings
- Layered memory: Short-term (current conversation) + Long-term (database persistence)
Challenge 2: Precise Diff Patch Application
How to precisely apply AI-generated modification suggestions to the original text?
- He walked into the room and saw a stranger.
+ He cautiously pushed open the door. In the dim room, a dark figure stood with its back to him.
Solution:
- Implemented
ApplyChapterPatchToolsupporting Unified Diff format - Used
java-diff-utilsfor precise text difference calculation - Real-time preview of modifications on frontend
Challenge 3: Multi-Model Tool Calling Differences
OpenAI, Claude, and Gemini have different function calling formats:
Solution:
- Abstract
ChatServiceinterface - Implement adapters for each model (Adapter Pattern)
- Unified tool registration and execution mechanism
π οΈ Tech Stack
Backend
| Technology | Version | Purpose |
|---|---|---|
| Java | 17 | Primary Language |
| Spring Boot | 3.3.5 | Application Framework |
| Spring AI | 1.0.2 | AI Model Integration |
| MyBatis Plus | 3.5.12 | ORM Framework |
| MySQL | 8.0 | Primary Database |
| Redis | - | Cache & Session Management |
| Sa-Token | 1.34.0 | Authentication & Authorization |
| WebSocket | - | Real-time Communication |
Frontend
| Technology | Version | Purpose |
|---|---|---|
| Vue | 3.5 | UI Framework |
| Vite | 6.0 | Build Tool |
| TipTap | 2.4 | Rich Text Editor |
| Element Plus | 2.9 | UI Component Library |
| Mermaid | 11.8 | Chart Rendering |
| AntV G6 | 4.8 | Relationship Graph Visualization |
| Tailwind CSS | 3.4 | Styling Framework |
| Tauri | 2.7 | Desktop App Packaging |
AI Services
| Service | Purpose |
|---|---|
| OpenAI API | GPT Series Models |
| Anthropic API | Claude Series Models |
| Google Vertex AI | Gemini Series Models |
| Dify | Workflow Orchestration (One-Click Write) |
Payment Integration
| Service | Purpose |
|---|---|
| WeChat Pay | Membership Subscription |
| Alipay | Membership Subscription |
π― Core Features
- AI Conversational Writing - Collaborate with AI to complete chapters
- Intelligent Tool Calling - AI automatically reads settings, searches content, modifies chapters
- Character Management - Complete character settings and relationship management
- Outline System - Multi-level outlines (master outline, volume outline, chapter outline)
- Chart Generation - Character relationship diagrams, plot timelines, faction distribution maps
- Prompt Marketplace - Share and use creative templates
- One-Click Writing - Automated writing based on Dify workflows
β οΈ Current Limitations & Honest Reflections
As a university student with limited budget, I want to be transparent about the current constraints:
1. Third-Party API Relay Services
Due to regional restrictions and cost considerations, I'm using third-party API relay services instead of direct official API access:
$$ \text{API Cost}{direct} \gg \text{Budget}{student} \Rightarrow \text{Solution: Relay Services} $$
Trade-offs:
- β Lower cost, accessible for students
- β Potential latency and stability issues
- β Limited access to the latest model versions
2. Tool Calling Accuracy
The models accessible through relay services are often not the top-tier versions, which affects the accuracy of function calling:
| Aspect | Ideal | Current Reality |
|---|---|---|
| Tool Selection | 95%+ accuracy | ~70-80% accuracy |
| Parameter Extraction | Precise | Sometimes misses context |
| Multi-step Reasoning | Reliable | Occasionally needs retry |
Why this happens:
- Premium models (GPT-4, Claude 3 Opus) have better tool-calling capabilities
- Budget constraints limit us to more affordable model tiers
- Complex writing tasks require sophisticated reasoning
3. What I Learned from These Limitations
These constraints actually taught me valuable lessons:
- Graceful Degradation: Design systems that handle AI failures gracefully
- User Feedback Loops: Let users correct AI mistakes and improve over time
- Cost-Aware Architecture: Build with scalability in mindβupgrade models when budget allows
"Constraints breed creativity. Building with limited resources taught me more than unlimited access ever could."
π Future Vision
$$ \text{Fiction AI}_{v2.0} = \text{Current Features} + \text{Writing Style Learning} + \text{Book Analysis} + \text{Community Collaboration} $$
- Writing Style Learning: Learn specific authors' writing styles
- Book Analysis: Analyze structure and techniques of excellent works
- Community Features: Author communication, work sharing
- Dynamic Model Selection: Automatically choose models based on task complexity
"AI is the pen, creativity is the ink, but the story always belongs to humanity."
Built With
- vue
Log in or sign up for Devpost to join the conversation.