让提取提示词序列化错误可恢复

将提取提示词生成改为返回带上下文的错误。
This commit is contained in:
2026-09-11 18:52:10 +08:00
parent 8d7ccc0d75
commit cf68b8212d
2 changed files with 4 additions and 4 deletions
@@ -45,7 +45,7 @@ pub(crate) fn gen_extract_prompt(
state: &SeparationState,
tree: &SeparationTree,
batch: &[&SeparationNode],
) -> String {
) -> Result<String, String> {
let mut result = r#"
This is a UI design image, not a normal photo/illustration. Extract it strictly as UI elements/layers, not as a generic foreground/background extraction.
Treat distinct UI element as its own layer with hard, clean, pixel-accurate edges and full transparency outside the element.
@@ -78,12 +78,12 @@ pub(crate) fn gen_extract_prompt(
ui_layer_tree: project_node(&tree.root, &target_ids, &terminal_ids, &mut index),
};
let yaml = serde_yaml::to_string(&document)
.expect("UI separation extract prompt projection must be serializable");
.map_err(|error| format!("UI separation extract prompt projection failed: {error}"))?;
result.push_str("```yaml\n");
result.push_str(&yaml);
result.push_str("```\n");
result
Ok(result)
}
fn project_node(
@@ -127,7 +127,7 @@ pub(crate) async fn separate_ui_impl(
break;
}
let batch = batch_nodes.iter().collect::<Vec<_>>();
let prompt = gen_extract_prompt(&separation, current_tree, &batch);
let prompt = gen_extract_prompt(&separation, current_tree, &batch)?;
app_log!(
"ui_separation.batch_start tree_index={} batch_index={} nodes={} area_px={} image_edit_dimension_px={} prompt_chars={} rework_total={}",
tree_index, batch_index, batch.len(), batch_area_px, image_edit_dimension_px,