Skip to content

fix: 修复 LLM 未正确输出完整章节内容导致的字数截断问题#67

Open
xiemobiao wants to merge 1 commit intoNarcooo:masterfrom
xiemobiao:fix/gemini-content-truncation
Open

fix: 修复 LLM 未正确输出完整章节内容导致的字数截断问题#67
xiemobiao wants to merge 1 commit intoNarcooo:masterfrom
xiemobiao:fix/gemini-content-truncation

Conversation

@xiemobiao
Copy link

问题描述

使用 Gemini(及其他模型)时,修订/分析流程可能产生字数极少的章节(如 3000+ 字变成 20 字)。

复现步骤

  1. 使用 Gemini 3 Flash Preview 作为 LLM
  2. 写章时触发 spot-fix(如出现禁止句式)
  3. 最终保存的章节字数可能只有几十字

根因分析

  1. ChapterAnalyzerAgent 要求 LLM 在 CHAPTER_CONTENT 中"原样输出"章节内容
  2. Gemini 不会可靠地输出完整内容(可能省略或截断)
  3. 截断后的内容长度被用作 wordCount,覆盖了正确的值

解决方案

  • buildPersistenceOutput 中直接使用 finalContent,不再依赖 LLM 回显
  • 添加字数守卫:修订后字数低于原文 50% 时拒绝修订
  • spot-fix 的 maxTokens 从 8192 提升到 16384
  • 强化 spot-fix 提示词,明确要求输出完整章节正文

测试

  • 使用 Gemini 3 Flash Preview 测试,字数截断问题已修复
  • 编译通过

🤖 Generated with Claude Code

问题:
使用 Gemini(及其他模型)时,修订/分析流程可能产生字数极少的章节
(如 3000+ 字变成 20 字)。原因是:

1. ChapterAnalyzerAgent 要求 LLM 在 CHAPTER_CONTENT 中"原样输出"章节内容
2. 部分模型(尤其是 Gemini)不会可靠地输出完整内容
3. 截断后的内容长度被用作 wordCount

解决方案:
- 在 buildPersistenceOutput 中直接使用 finalContent,不再依赖 LLM 回显
- 添加字数守卫:修订后字数低于原文 50% 时拒绝修订
- spot-fix 的 maxTokens 从 8192 提升到 16384
- 强化 spot-fix 提示词,明确要求输出完整章节正文

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant