diff --git a/desktop/core/providers.mjs b/desktop/core/providers.mjs index c7a804d..bde0459 100644 --- a/desktop/core/providers.mjs +++ b/desktop/core/providers.mjs @@ -88,7 +88,7 @@ const PLACEHOLDER=/尚未|等待|采样窗口|时间采样|语义或动作/; const TITLE_CARD=/标题画面|演职员|职员表|片头|片尾|字幕卡|制作人员/; const SEG_CAP=60,PER_MEDIA_CAP=8,DESC_MAX=90; const round2=n=>Math.round(n*100)/100; -function buildProjectData(p,budget){ +function buildProjectData(p,budget,fresh){ const media=p.media.map(m=>{ const seen=new Set(); const all=(m.analysis?.segments||[]).filter(s=>s&&Number.isFinite(s.score)&&s.score!==null&&typeof s.description==='string'&&s.description&&!PLACEHOLDER.test(s.description)&&!TITLE_CARD.test(s.description)&&!seen.has(s.description)&&(seen.add(s.description),true)) @@ -99,10 +99,10 @@ function buildProjectData(p,budget){ media.sort((a,b)=>(b.segments[0]?.score??-1)-(a.segments[0]?.score??-1)); const kept=new Map();let cap=SEG_CAP; for(const m of media){const out=[];for(const s of m.segments){const n=kept.get(m.id)||0;if(n>=PER_MEDIA_CAP||!cap)break;kept.set(m.id,n+1);cap--;out.push(s);}m.segments=out;} - const clips=p.clips.map(c=>({id:c.id,...(c.mediaId?{mediaId:c.mediaId}:{}),track:c.track,start:round2(c.start),in:round2(c.in),out:round2(c.out),speed:c.speed??1,volume:c.volume??1, + const clips=fresh?[]:p.clips.map(c=>({id:c.id,...(c.mediaId?{mediaId:c.mediaId}:{}),track:c.track,start:round2(c.start),in:round2(c.in),out:round2(c.out),speed:c.speed??1,volume:c.volume??1, ...(c.fade!==undefined?{fade:c.fade}:{}),...(c.text?{text:c.text.slice(0,200)}:{}),...(c.color?{color:c.color}:{}),...(c.fontSize?{fontSize:c.fontSize}:{}), ...(c.brightness!==undefined?{brightness:c.brightness}:{}),...(c.contrast!==undefined?{contrast:c.contrast}:{}),...(c.saturation!==undefined?{saturation:c.saturation}:{}),...(c.fit?{fit:c.fit}:{})})); - const data={settings:p.settings,timelineDuration:round2(Math.max(0,...p.clips.map(c=>c.start+(c.out-c.in)/(c.speed||1)))),media,clips}; + const data={settings:p.settings,timelineDuration:fresh?0:round2(Math.max(0,...p.clips.map(c=>c.start+(c.out-c.in)/(c.speed||1)))),media,clips}; const steps=[ d=>{for(const m of d.media)m.segments=m.segments.slice(0,6);}, d=>{for(const m of d.media)for(const s of m.segments)s.description=s.description.slice(0,60);}, @@ -138,7 +138,7 @@ function buildHistoryBlock(history,budget){ } export function plannerPrompt(p,instruction,{fresh=false,target=0,style=null,budget=9000,history=[]}={}){ const historyBlock=buildHistoryBlock(history,Math.max(400,Math.round(budget*.35))); - const data=buildProjectData(p,Math.max(1200,budget-historyBlock.length)); + const data=buildProjectData(p,Math.max(1200,budget-historyBlock.length),fresh); const hasSegments=data.media.some(m=>m.segments.length); const mode=fresh?'用户要求创作新的时间轴:先 remove 现有全部片段,再按新要求重新 add;内容全部重新编排,不要保留旧镜头。':'时间轴需要保留:只修改用户明确提到的片段与字段,其余片段保持原样;不要删除未提及的片段,不要重建整个时间轴。'; const styleBlock=style?`风格参数(仅用于新添加的片段,不要改动现有片段):${JSON.stringify(style)}`:''; diff --git a/tests/providers.test.mjs b/tests/providers.test.mjs index 0e02ce2..3738a6c 100644 --- a/tests/providers.test.mjs +++ b/tests/providers.test.mjs @@ -50,11 +50,17 @@ test('规划提示词:按评分筛选片段、丢弃占位描述、区分新 assert.ok(!fresh.includes('motion')); assert.ok(fresh.includes('先 remove 现有全部片段')); assert.ok(fresh.includes('45')); + // 新建模式:数据中不带旧时间轴(避免模型被旧片段干扰) + const freshData=JSON.parse(fresh.slice(fresh.indexOf('{',fresh.indexOf('项目数据')))); + assert.equal(freshData.clips.length,0); + assert.equal(freshData.timelineDuration,0); assert.ok(fresh.includes('score')); assert.ok(fresh.length<12000); const modify=plannerPrompt(p,'把第一个镜头缩短一点',{fresh:false,budget:9000}); assert.ok(modify.includes('时间轴需要保留')); assert.ok(modify.includes('c1')); + const modifyData=JSON.parse(modify.slice(modify.indexOf('{',modify.indexOf('项目数据')))); + assert.equal(modifyData.clips.length,1); // 大数据量下仍受预算约束 const big={settings:p.settings,media:Array.from({length:40},(_,i)=>({id:'m'+i,name:'素材'+i,type:'video',duration:300,tags:['t'],analysis:{segments:Array.from({length:10},(_,j)=>({start:j*30,end:j*30+28,description:'第'+j+'段:这是很长的一段语义描述内容用来填充上下文窗口测试预算裁剪是否生效',score:99-j}))}})),clips:Array.from({length:60},(_,i)=>({id:'c'+i,mediaId:'m0',track:'video',start:i*5,in:0,out:5,speed:1,volume:1}))}; const small=plannerPrompt(big,'重新剪一遍',{fresh:true,budget:3800});