fix: 修复ComfyUI工作流提示词替换和错误判断逻辑

- 优化节点识别逻辑,正确识别模特描述节点为提示词类型
- 根据节点class_type智能选择替换字段(String类型用value,其他用text)
- 修复ComfyUI错误判断逻辑,空node_errors对象不再误判为失败
- 确保ComfyUI任务成功创建时不会被错误标记为失败状态
- 提升工作流执行成功率和用户体验
This commit is contained in:
imeepos 2025-07-30 21:51:35 +08:00
parent d5d9202e86
commit e880687004
1 changed files with 45 additions and 5 deletions

View File

@ -308,11 +308,11 @@ impl ComfyUIService {
if let Some(Value::String(title)) = meta.get("title") {
if title.contains("BOWONG-INPUT-") {
should_replace = true;
if title.contains("模特") || title.contains("MODEL") || title.contains("AVATAR") {
if title.contains("模特") && !title.contains("描述") {
replacement_type = "model";
} else if title.contains("穿搭") || title.contains("商品") || title.contains("PRODUCT") || title.contains("CLOTH") {
replacement_type = "product";
} else if title.contains("提示") || title.contains("PROMPT") || title.contains("TEXT") {
} else if title.contains("提示") || title.contains("PROMPT") || title.contains("TEXT") || title.contains("描述") {
replacement_type = "prompt";
} else if title.contains("负面") || title.contains("NEGATIVE") {
replacement_type = "negative";
@ -364,17 +364,48 @@ impl ComfyUIService {
});
}
"prompt" => {
// 根据节点类型决定使用哪个字段
let field_name = if let Value::Object(node_obj) = node_value {
if let Some(Value::String(class_type)) = node_obj.get("class_type") {
if class_type == "String" {
"value"
} else {
"text"
}
} else {
"text"
}
} else {
"text"
};
replacements.push(WorkflowNodeReplacement {
node_id: node_id.clone(),
input_field: "text".to_string(),
input_field: field_name.to_string(),
value: Value::String(prompt.to_string()),
});
}
"negative" => {
let neg_prompt = negative_prompt.unwrap_or("");
// 根据节点类型决定使用哪个字段
let field_name = if let Value::Object(node_obj) = node_value {
if let Some(Value::String(class_type)) = node_obj.get("class_type") {
if class_type == "String" {
"value"
} else {
"text"
}
} else {
"text"
}
} else {
"text"
};
replacements.push(WorkflowNodeReplacement {
node_id: node_id.clone(),
input_field: "text".to_string(),
input_field: field_name.to_string(),
value: Value::String(neg_prompt.to_string()),
});
}
@ -438,7 +469,16 @@ impl ComfyUIService {
.map_err(|e| ComfyUIError::NetworkError(format!("解析响应失败: {}", e)))?;
if let Some(errors) = prompt_response.node_errors {
return Err(ComfyUIError::WorkflowError(format!("节点错误: {}", errors)));
// 检查是否真的有错误(不是空对象)
if let Value::Object(error_map) = &errors {
if !error_map.is_empty() {
return Err(ComfyUIError::WorkflowError(format!("节点错误: {}", errors)));
}
} else if errors != Value::Object(serde_json::Map::new()) {
return Err(ComfyUIError::WorkflowError(format!("节点错误: {}", errors)));
}
// 如果是空对象 {} 则不认为是错误
info!("收到空的节点错误对象,继续执行");
}
info!("工作流提交成功,提示 ID: {}", prompt_response.prompt_id);