feat(ai): 对话历史先压缩再发送,长会话关键意图不丢失

- buildHistoryBlock 把聊天历史压成「用户要求 + 助手执行摘要」的结构化记录
- 按预算逐级压缩:先缩短单条(120/80/50/30/20/15/10 字),再减少保留轮数(16→12→8→5→4),而不是简单截断
- 本地模型历史预算为总预算的 35%,云端更宽裕
- 规划时携带最近 16 轮原始消息(由压缩器决定保留量)
- 有音频素材且用户要求配乐/配音时,应添加 audio 轨并调整 volume
- 新增长对话压缩测试(12 轮历史不撑爆预算且末轮内容保留)
This commit is contained in:
xhgit committed 2026-11-14 12:24:42 +08:00
1 parent 6221828da2
commit d94e3eadfa
3 files changed
+28 -6

No files matched your search

+6
View File
@@ -59,6 +59,12 @@ test('规划提示词:按评分筛选片段、丢弃占位描述、区分新
assert.ok(withHist.includes('把片头字幕删掉'));
assert.ok(withHist.includes('对话记录'));
assert.ok(withHist.includes('不得以「未收到具体要求」为由返回空方案'));
// 长对话压缩:12 轮长历史也不会撑爆预算,且最后几轮的关键内容仍在
const longHist=Array.from({length:12},(_,i)=>({role:'user',text:`第${i+1}轮:把视频改成${60+i}秒,人物要多一点,画面换成主角和伙伴一起`})).flatMap((u,i)=>[u,{role:'assistant',text:`已按第${i+1}轮要求调整时间轴,共使用${5+i}个片段`}]);
const compressed=plannerPrompt(p,'按最后一轮的要求再调整一下',{history:longHist,budget:3800});
assert.ok(compressed.includes('第12轮'));
assert.ok(compressed.includes('第11轮'));
assert.ok(compressed.length<7000);
// 素材未分析时明确拦截:不允许凭空假设或整段取用
const raw={settings:p.settings,media:[{id:'u',name:'未分析素材',type:'video',duration:600,tags:[]}],clips:[]};
const unanalyzed=plannerPrompt(raw,'剪一个鲁迪和希露菲在一起的片段',{budget:9000});