fix(xiaoyi): assemble slot prompts before dispatch
This commit is contained in:
parent
b8ceb54a17
commit
62a6f21618
@ -557,7 +557,7 @@ fn candidate_prompt(
|
||||
field.get("name").or(field.get("label")).unwrap_or(&field["fieldId"]), field["role"])
|
||||
};
|
||||
format!(
|
||||
"【参考图顺序与用途】{}。product 是同款产品原片,产品外观只取自这些实物图。scene、模板和旧候选只供参考氛围、调性、色调、光影、背景、景别、镜头角度与留白,不提供商品造型。\n【外观约束】先按 product 锁定部件数量、轮廓、相对位置、连接方式、长宽高关系及可见空隙,再布景取景。近景和特写只改变同款商品在画框里的取景范围,保留目标部件与相邻接合、边缘和留空。模板镜头暴露原片无法确认的结构时,选最接近的实物可证机位,或让该部分自然出画或遮挡。图位与文案指定要展示的内容,产品结构始终服从同款原片。\n【当前图位】模板{};{target};画幅{}×{}。只生成铺满此图位的一张连续画面。标题、卖点、标签及尺寸由画布文字层排版;图片内不得加入文字、边框、拼版、现成页面或外部装饰白边。\n【产品事实】{}\n{visual_brief}\n【本图产品颜色】{}",
|
||||
"【参考图顺序与用途】{}。product 是同款产品原片,产品外观只取自这些实物图。scene、模板和旧候选只供参考氛围、调性、色调、光影、背景、景别、镜头角度与留白,不提供商品造型。\n【外观约束】先按 product 锁定部件数量、轮廓、相对位置、连接方式、长宽高关系及可见空隙,再布景取景。近景和特写只改变同款商品在画框里的取景范围,保留目标部件与相邻接合、边缘和留空。模板镜头暴露原片无法确认的结构时,选最接近的实物可证机位,或让该部分自然出画或遮挡。图位与文案指定要展示的内容,产品结构始终服从同款原片。\n【当前图位】模板{};{target};画幅{}×{}。只生成铺满此图位的一张连续画面。保留实拍里商品原有的标识。标题、卖点、标签及尺寸由画布文字层排版;图片内不得加入文字、边框、拼版、现成页面或外部装饰白边。\n【产品事实】{}\n{visual_brief}\n【本图产品颜色】{}",
|
||||
json!(references), state["template"]["name"], field["frame"]["width"], field["frame"]["height"], product, color_rule
|
||||
)
|
||||
}
|
||||
@ -3273,18 +3273,28 @@ impl Backend {
|
||||
let base_index = images.as_array().map_or(0, Vec::len) + 1;
|
||||
prompt.push_str(&refinement_prompt(base_index));
|
||||
}
|
||||
let knowledge = if state["template"]["enterprise"].is_object() && input["detailBatch"] != true {
|
||||
self.enterprise_template_request(json!({"action":"context","projectRoot":dir,"task":"image","brandName":state["brief"]["brandName"],"categoryName":state["brief"]["categoryName"],"templateId":state["template"]["id"],"releaseId":state["template"]["version"]}))?["context"].clone()
|
||||
} else { Value::Null };
|
||||
if scene.is_none() {
|
||||
let profile = &creation["designSnapshot"]["brand"]["profile"];
|
||||
let visual = profile["visualRules"].as_object().map(|values|
|
||||
values.values().filter_map(Value::as_str).collect::<Vec<_>>().join("\n")).unwrap_or_default();
|
||||
let brand = if knowledge.is_null() {
|
||||
json!({"name":creation["brief"]["brandName"],"tone":profile["tone"],"visualRules":visual})
|
||||
} else { json!({"name":creation["brief"]["brandName"],"knowledge":knowledge}) };
|
||||
let guidance = json!({"brand":brand,"facts":creation["facts"]});
|
||||
prompt.push_str(&format!("\n【品牌与已确认资料】{guidance}"));
|
||||
}
|
||||
if prefer_2k {
|
||||
prompt.push_str("\n局部证据请用稍宽的原始取景拍摄。保留目标部位与相邻的真实接合关系,将目标留在画面中心附近,并预留四周以便按最终图框裁切。");
|
||||
}
|
||||
if let Some(position) = layout_position {
|
||||
prompt.push_str(&format!(
|
||||
"{}第{position}张是本图位的取景底稿。保留参考的镜头角度、景别、主体占幅、布景与背景关系、光源方向、明暗和色调,以及人物位置、动作和排字留白。图位明确要求调整的构图和动作按本图位要求执行。将底稿中的旧商品换成本项目原片中的同款商品,其余保持原位,仅调整与新商品摆放、透视、接触和阴影有关的区域。旧商品轮廓、比例、部件、连接、空隙和表面一律以同款原片替换。清除模板文字、遮罩、虚线、尺寸和坐标。",
|
||||
super::images::TEMPLATE_LAYOUT_PROMPT_PREFIX
|
||||
));
|
||||
}
|
||||
if prefer_2k {
|
||||
prompt.push_str("\n局部证据请用稍宽的原始取景拍摄。保留目标部位与相邻的真实接合关系,将目标留在画面中心附近,并预留四周以便按最终图框裁切。");
|
||||
}
|
||||
let knowledge = if state["template"]["enterprise"].is_object() && input["detailBatch"] != true {
|
||||
self.enterprise_template_request(json!({"action":"context","projectRoot":dir,"task":"image","brandName":state["brief"]["brandName"],"categoryName":state["brief"]["categoryName"],"templateId":state["template"]["id"],"releaseId":state["template"]["version"]}))?["context"].clone()
|
||||
} else { Value::Null };
|
||||
let mut binding = new_binding(&state, &output, &field, &id, &variant_id, &candidate, &prompt);
|
||||
if input["detailBatch"] == true { binding["detailBatch"] = json!(true); }
|
||||
if !attachment_refs.as_array().is_none_or(Vec::is_empty) { binding["composerHash"] = json!(hash(&attachment_refs.to_string())); }
|
||||
@ -3300,12 +3310,8 @@ impl Backend {
|
||||
}
|
||||
publish_prepared(events, snapshot)?;
|
||||
ctx.request_repaint();
|
||||
let profile = &creation["designSnapshot"]["brand"]["profile"];
|
||||
let visual =
|
||||
profile["visualRules"].as_object().map(|values| values.values().filter_map(Value::as_str).collect::<Vec<_>>().join("\n")).unwrap_or_default();
|
||||
let brand = json!({"name":creation["brief"]["brandName"],"tone":profile["tone"],"visualRules":visual,"fontFamily":"Noto Sans SC"});
|
||||
let request_frame = image_ratio.map_or_else(|| field["frame"].clone(), |(width,height)| json!({"width":width,"height":height}));
|
||||
let call = self.image_job_with_scene(Some(Arc::new(references)), &json!({"doc":doc,"revision":input["baseRevision"],"model":model,"mode":if parent.is_some(){"refine"}else{"generate"},"text":prompt,"screen":output["name"],"references":layers,"hasTemplateLayout":layout_position.is_some(),"optionalLayoutReference":layout_position.is_some()&&!fixed_layout,"slotBinding":binding,"slotFrame":request_frame,"prefer2k":prefer_2k,"brand":if knowledge.is_null(){brand}else{json!({"name":creation["brief"]["brandName"],"knowledge":knowledge})},"facts":creation["facts"]}), false, events, ctx, scene);
|
||||
let call = self.image_job_with_scene(Some(Arc::new(references)), &json!({"doc":doc,"revision":input["baseRevision"],"model":model,"mode":if parent.is_some(){"refine"}else{"generate"},"text":prompt,"references":layers,"optionalLayoutReference":layout_position.is_some()&&!fixed_layout,"slotBinding":binding,"slotFrame":request_frame,"prefer2k":prefer_2k}), false, events, ctx, scene);
|
||||
let file = dir.join("image-jobs").join(&candidate).join("task.json");
|
||||
let mut journal =
|
||||
if file.try_exists().map_err(|_| "原生图记录无法核对,保留原候选")? {
|
||||
|
||||
@ -59,6 +59,13 @@ pub(super) fn agent_color_preview(decoded: photocraft_codecs::Image) -> egui::Co
|
||||
|
||||
pub(super) const TEMPLATE_LAYOUT_PROMPT_PREFIX: &str = "\n【模板图位参考】";
|
||||
|
||||
fn slot_transport_prompt(text: &str, omit_optional_layout: bool) -> &str {
|
||||
if omit_optional_layout {
|
||||
return text.rsplit_once(TEMPLATE_LAYOUT_PROMPT_PREFIX).map_or(text, |(instructions, _)| instructions);
|
||||
}
|
||||
text
|
||||
}
|
||||
|
||||
pub(super) fn reference_preview_id(id: &str) -> bool {
|
||||
id.strip_prefix("ref-").is_some_and(|digest| digest.len() == 64 && digest.bytes().all(|byte| byte.is_ascii_hexdigit()))
|
||||
}
|
||||
@ -678,16 +685,7 @@ impl Backend {
|
||||
}
|
||||
}
|
||||
let text = input["text"].as_str().filter(|s| !s.trim().is_empty()).ok_or("请输入生图要求")?;
|
||||
let (text, template_reference) = if input["hasTemplateLayout"] == true || input["optionalLayoutReference"] == true {
|
||||
text.rsplit_once(TEMPLATE_LAYOUT_PROMPT_PREFIX).unwrap_or((text, ""))
|
||||
} else {
|
||||
(text, "")
|
||||
};
|
||||
let template_reference = if omit_layout || template_reference.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!("{TEMPLATE_LAYOUT_PROMPT_PREFIX}{template_reference}")
|
||||
};
|
||||
let text = slot_transport_prompt(text, omit_layout);
|
||||
let job = if input["slotBinding"].is_object() {
|
||||
super::template_slots::validate_dispatch(&dir, &input["slotBinding"])?;
|
||||
input["slotBinding"]["taskId"].as_str().ok_or("图位候选身份无效")?.to_owned()
|
||||
@ -717,24 +715,23 @@ impl Backend {
|
||||
job_bytes(&dir, &path, &bytes).map_err(|_| "参考图保存失败,未提交")?;
|
||||
references.push(json!({"layer":layer.0,"name":name,"path":path.to_string_lossy(),"sha256":format!("{:x}",Sha256::digest(&bytes))}));
|
||||
}
|
||||
let guidance = json!({"brand":input["brand"],"facts":input["facts"]});
|
||||
let color_rule = if input["slotBinding"]["canvasFirst"] == true {
|
||||
"产品颜色服从【本图产品颜色】。"
|
||||
} else {
|
||||
"严格保留参考图中的产品颜色。"
|
||||
};
|
||||
let prompt = if let Some((_,cutout)) = &scene {
|
||||
if let Some((_,cutout)) = &scene {
|
||||
if references.len() != 1 { return Err("实拍合成只发送模板场景去除旧商品".into()); }
|
||||
job_bytes(&dir, &files.join("scene-product.png"), cutout).map_err(|_| "实拍抠图保存失败,未提交")?;
|
||||
}
|
||||
let prompt = if input["slotBinding"]["canvasFirst"] == true || scene.is_some() {
|
||||
text.to_owned()
|
||||
} else { format!(
|
||||
"【产品本体优先】只按本项目同款实物图保留外形、结构、部件连接、间隙、材质、比例及数量。场景图、旧候选或模板仅用于氛围、调性、色调、光影、景别、镜头角度和布景。近景和特写以同款实物为主体另行取景,未确认部位不补画。{color_rule}{template_reference}\n生成一张产品图,保留实物可见的原有铭牌和固定标记,不编造模糊字样。标题、字幕、角标、水印和尺寸标注交给画布。各屏保持摄影风格与光线一致。\n项目:{}\n当前屏:{}\n项目规范与已确认事实(规范指导风格及版式,已确认事实与实物图提供商品依据):{guidance}\n要求:{text}",
|
||||
doc.name,
|
||||
input["screen"].as_str().unwrap_or("当前图片")
|
||||
) };
|
||||
} else {
|
||||
let guidance = json!({"brand":input["brand"],"facts":input["facts"]});
|
||||
format!(
|
||||
"【产品本体优先】只按本项目同款实物图保留外形、结构、部件连接、间隙、材质、比例及数量。场景图、旧候选或模板仅用于氛围、调性、色调、光影、景别、镜头角度和布景。近景和特写以同款实物为主体另行取景,未确认部位不补画。严格保留参考图中的产品颜色。\n生成一张产品图,保留实物可见的原有铭牌和固定标记,不编造模糊字样。标题、字幕、角标、水印和尺寸标注交给画布。各屏保持摄影风格与光线一致。\n项目:{}\n当前屏:{}\n项目规范与已确认事实(规范指导风格及版式,已确认事实与实物图提供商品依据):{guidance}\n要求:{text}",
|
||||
doc.name,
|
||||
input["screen"].as_str().unwrap_or("当前图片")
|
||||
)
|
||||
};
|
||||
protocol::validate_prompt_length(&contract, &prompt)?;
|
||||
let prior = if dir.join("image-task.json").exists() { read_json(&dir.join("image-task.json"))?["id"].clone() } else { Value::Null };
|
||||
json!({"version":1,"id":job,"doc":id,"revision":input["revision"],"mode":input["mode"],"target":target,"modelId":model_id,"modelKey":choice,"protocol":contract,"prompt":prompt,"references":references,"keyFingerprint":hash(key),"phase":"prepared","requestId":null,"upstreamTaskId":null,"center":input["center"],"accountScope":self.scope(),"localProjectId":self.locations.get(&id),"origin":self.origin,"createdAt":now(),"replacesTaskId":prior,"creationBinding":input["creationBinding"],"slotBinding":input["slotBinding"],"sceneComposite":scene.as_ref().map(|(recipe,_)|recipe)})
|
||||
json!({"version":1,"id":job,"doc":id,"revision":input["revision"],"mode":input["mode"],"target":target,"modelId":model_id,"modelKey":choice,"protocol":contract,"prompt":prompt,"references":references,"omittedOptionalLayout":omit_layout,"keyFingerprint":hash(key),"phase":"prepared","requestId":null,"upstreamTaskId":null,"center":input["center"],"accountScope":self.scope(),"localProjectId":self.locations.get(&id),"origin":self.origin,"createdAt":now(),"replacesTaskId":prior,"creationBinding":input["creationBinding"],"slotBinding":input["slotBinding"],"sceneComposite":scene.as_ref().map(|(recipe,_)|recipe)})
|
||||
};
|
||||
if t["keyFingerprint"] != hash(key) {
|
||||
return Err("请切回原个人Key,只读核查原请求;不会重发".into());
|
||||
@ -1035,6 +1032,15 @@ impl Backend {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn slot_dispatch_preserves_prompt_and_prepares_optional_reference_before_freeze() {
|
||||
let instructions = "同款实拍。品牌用侧光。用稍宽画面留出裁切空间。";
|
||||
let prompt = format!("{instructions}{TEMPLATE_LAYOUT_PROMPT_PREFIX}第 3 张仅作构图参考。");
|
||||
assert_eq!(slot_transport_prompt(&prompt, false).as_bytes(), prompt.as_bytes());
|
||||
assert_eq!(slot_transport_prompt(&prompt, true), instructions);
|
||||
assert_eq!(slot_transport_prompt(instructions, true), instructions);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_thumbnail_is_pending_until_the_jpeg_is_published() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
@ -522,3 +522,5 @@ R7 原生 `f101fda3`、Agent `4ee5a5b4` 用最新构建新建电脑桌项目,
|
||||
### 生图冻结记录与派发内容
|
||||
|
||||
电脑桌真实项目保留 22 笔已获得原编号的普通图请求。按同一任务目录逐笔比较,候选冻结的提示词与原生 POST 使用的任务提示词全部不同,模型相同。示例请求从 5,367 字节增加至 6,653 字节。代码确认适配层在候选冻结以后加入商品结构说明及项目事实,再持久化任务并使用任务字段发 POST。该批仍可追到原请求与实际参考图,P03 的逐字一致性未通过。证据 `batch-09/desk-reconcile-r6/frozen-candidate-vs-final-transport.json`。
|
||||
|
||||
图位提示词现在在候选预留前完成品牌、已确认资料、取景和同款结构的拼装。正常线路使用原文字节。线路确实省略可选模板参考时,任务先调整最后的参考段并记录省略,再持久化实际请求。2K 的取景要求在可省略段之前。较早的独立生图入口沿用自己的输入组织。33 项原生图像任务测试通过,`batch-09/image-transport-prompt-native.log`。R7 使用本改动之前的构建,实际派发复验待下一轮。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user