Skip to content

Feat/auto detect max tokens - #163

Open
leonluo2008-ops wants to merge 8 commits into
RhythmicWave:mainfrom
leonluo2008-ops:feat/auto-detect-max-tokens
Open

Feat/auto detect max tokens#163
leonluo2008-ops wants to merge 8 commits into
RhythmicWave:mainfrom
leonluo2008-ops:feat/auto-detect-max-tokens

Conversation

@leonluo2008-ops

Copy link
Copy Markdown

改动概述

文件改动说明

验证

硬编码 max_tokens=64 会让 thinking 模型(如 deepseek-v4-flash)把预算全花在思考上,
正文输出为空,导致 basic_chat 被误判为 fail、整体判定 unusable。

改为从 64 起逐步放大探测,找到非空响应后再向上确认一个更大的稳定值,
对 thinking 模型自动放宽,普通模型保持小值省 token。
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Phase1 根因①修复:
1. _build_continuation_user_prompt: previous_content 分支强化续写指令
   - 明确前文人称/时代/场景/角色必须延续,禁止切换人称/世界观/更换主角
   - 禁止引入上下文未提及的新角色
   - 禁止重复前文已写内容
2. continuation_budget_runtime: close_mode 阈值 1000→1500,避免 remaining
   略高于 1000 时建议规模被压到下限导致写不满
3. llm_service: 多轮续写空输出重试一次,避免偶发空响应提前结束

回归结果:第3章跑飞(第一人称现代宅邸)已修复,人称/场景/材质/角色
全部保持,beat 全贴,无重复段。
- context_service: 新增 _build_character_summaries,兼容 R1/R2 卡 schema
- context_service: 同名卡去重(R1 旧卡不再污染检索结果)
- schemas/context: CharacterSummary model + character_summaries 字段
- continuation_context_service: _format_facts_structured 输出角色/物品/概念/关系摘要
- ai.py: system prompt 追加实体设定优先级提醒,防前文稀释设定约束
- count_text_units: 去空白全字符 -> 纯汉字 (re.findall [\u4e00-\u9fff])
- _take_text_by_units: 流式硬截断同口径,标点不占配额
- _resolve_current_word_count: previous_content 优先重算,防御前端口径漂移
- 前端 computeWordCount: 同口径,字数显示与预算一致
previous_content 是上章衔接上下文,不应覆盖 existing_word_count。
前端 computeWordCount 已改为纯汉字口径,防御重算不再需要。
根因:llm_service 多轮循环把 previous_content(prev_tail)加到
current_content 并计入字数统计,导致 ch2/ch3 提前触发字数达标退出。

修改:
1. llm_service: current_word_count 初始从 existing_word_count 取(不回退previous_content)
2. llm_service: current_content 初始化为空,previous_content 保留为上下文参考
3. llm_service: 每轮 round_request.previous_content = 原始prev_tail + 已生成内容
4. _find_sentence_cut/_find_hard_cut: char.isspace() → 纯汉字范围判断
…red 误判

能力检测所有 probe 共用同一 max_tokens,而结构化输出(structured)比简单 ping
需要更多预算。旧逻辑只按 basic_chat 判空取第一个通过档(如128),导致 thinking
模型(如 gemini-3.6-flash)在预算耗尽时结构化输出返回空、被误判 fail(plain_only)。

修复:每个候选档同时校验 basic_chat 非空 + 结构化输出有效,并取第二个通过档
(留余量抹平临界波动),确保返回值对 downstream 全链路足够。同时修复 try_repair
分支下能力检测结果未回写配置的问题。
@RhythmicWave

Copy link
Copy Markdown
Owner

感谢贡献,但最好需要完成:

  1. CLA协议
  2. 概述所有的改动及影响

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.

3 participants