feat(ai): 规划提示词重写——按评分选材、数据预算控制与新建/修改模式
- 只发送有评分且非占位描述的片段,按 score 排序,每素材最多 8 段、全局最多 60 段 - 新增选材规则:优先高分片段、按主题匹配、多素材分散、禁止无关素材与编造音乐 - 提示词数据按预算逐级裁剪(本地模型 3800 字符),避免超出上下文窗口报错 - 区分新建创作与局部修改模式,新建时先清空再重建,修改时只动提及字段 - 明确数值范围与时间轴规则(不重叠、时长=(out-in)/speed、图片最长 60 秒)
This commit is contained in:
1 parent
61cff864b9
commit
7d9a7a777e
2 files changed
+90
-6
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import {test} from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import {complete,listModels,parseJson} from '../desktop/core/providers.mjs';
|
||||
import {complete,listModels,parseJson,plannerPrompt} from '../desktop/core/providers.mjs';
|
||||
import {getStyle} from '../desktop/core/styles.mjs';
|
||||
test('适配器协议合约(本机测试服务器,不代表云端联调)',async()=>{
|
||||
let body,url,headers;const server=http.createServer(async(req,res)=>{let data='';for await(const part of req)data+=part;body=data?JSON.parse(data):null;url=req.url;headers=req.headers;res.setHeader('Content-Type','application/json');if(req.url==='/api/chat')res.end(JSON.stringify({message:{content:'{"ok":true}'},eval_count:4}));else if(req.url==='/messages')res.end(JSON.stringify({content:[{type:'text',text:'{"ok":true}'}]}));else if(req.url.includes('generateContent'))res.end(JSON.stringify({candidates:[{content:{parts:[{text:'{"ok":true}'}]}}]}));else if(req.url==='/models')res.end(JSON.stringify({data:[{id:'test-only'}]}));else res.end(JSON.stringify({choices:[{message:{content:'{"ok":true}'}}]}));});
|
||||
await new Promise(r=>server.listen(0,'127.0.0.1',r));const baseUrl=`http://127.0.0.1:${server.address().port}`;
|
||||
@@ -30,3 +31,27 @@ test('JSON 解析失败自动重试:第二次不再强制 format 并追加严
|
||||
assert.ok(calls[1].messages[0].content.includes('只输出一个 JSON 对象'));
|
||||
}finally{server.closeAllConnections();server.close();}
|
||||
});
|
||||
test('规划提示词:按评分筛选片段、丢弃占位描述、区分新建/修改模式、控制数据体量',()=>{
|
||||
const mk=(id,score)=>({id,name:id,type:'video',duration:120,tags:['海边'],analysis:{segments:[
|
||||
{start:0,end:5,description:'海滩日落,人物走过画面,光线柔和,构图开阔',score,reason:'构图好'},
|
||||
{start:10,end:15,description:'尚未进行语义或动作识别',score:null},
|
||||
{start:20,end:25,description:'城市夜景,车流灯光',score:score-10,reason:'节奏感强'},
|
||||
]}});
|
||||
const p={settings:{width:1920,height:1080,fps:30},media:[mk('a',90),mk('b',40)],clips:[{id:'c1',mediaId:'a',track:'video',start:0,in:0,out:5,speed:1,volume:1,motion:[{time:0,zoom:1,x:.5,y:.5}],text:'旧字幕'}]};
|
||||
const fresh=plannerPrompt(p,'制作一个旅行短片',{fresh:true,target:45,style:getStyle('cinematic'),budget:9000});
|
||||
assert.ok(fresh.includes('海滩日落'));
|
||||
assert.ok(fresh.includes('城市夜景'));
|
||||
assert.ok(!fresh.includes('尚未进行语义或动作识别'));
|
||||
assert.ok(!fresh.includes('motion'));
|
||||
assert.ok(fresh.includes('先 remove 现有全部片段'));
|
||||
assert.ok(fresh.includes('45'));
|
||||
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 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});
|
||||
assert.ok(small.length<6500);
|
||||
});
|
||||
Reference in new issue
Block a user