fix: 修复工作流入口标题与提示词校验
- 支持系统入口标题清空占位与下游引用展示同步 - 降低字段编辑触发的节点图重算和无效渲染 - 在保存及执行前拦截空白的大模型用户提示词
This commit is contained in:
@@ -832,11 +832,36 @@ public class WorkflowCheckService {
|
||||
continue;
|
||||
}
|
||||
if (workflowDatacenterContentService.isLlmNode(node.type)) {
|
||||
checkLlmUserPrompt(node, issues, issueKeys);
|
||||
checkLlmQueryContext(node, parsed, issues, issueKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验大模型节点的用户提示词,避免空提示词进入运行时解析。
|
||||
*
|
||||
* @param node 大模型节点
|
||||
* @param issues 问题列表
|
||||
* @param issueKeys 问题去重键
|
||||
*/
|
||||
private void checkLlmUserPrompt(
|
||||
NodeView node,
|
||||
List<WorkflowCheckIssue> issues,
|
||||
Set<String> issueKeys) {
|
||||
String userPrompt = node.data == null ? null : node.data.getString("userPrompt");
|
||||
if (!StringUtils.hasText(userPrompt)) {
|
||||
addIssue(
|
||||
issues,
|
||||
issueKeys,
|
||||
"LLM_USER_PROMPT_EMPTY",
|
||||
"大模型节点的用户提示词不能为空",
|
||||
node.id,
|
||||
null,
|
||||
node.name);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMakeFileNode(NodeView node,
|
||||
List<WorkflowCheckIssue> issues,
|
||||
Set<String> issueKeys) {
|
||||
|
||||
@@ -436,6 +436,41 @@ public class WorkflowCheckServiceTest {
|
||||
assertHasCode(result, "SEARCH_DATASET_INVALID");
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证保存阶段拒绝空白的大模型用户提示词。
|
||||
*/
|
||||
@Test
|
||||
public void testSaveShouldBlockBlankLlmUserPrompt() throws Exception {
|
||||
WorkflowCheckService service = newService(new HashMap<>());
|
||||
JSONObject llmData = data("大模型");
|
||||
llmData.put("userPrompt", " ");
|
||||
String content = workflowJson(
|
||||
array(node("llm-1", "llmNode", null, llmData)),
|
||||
new JSONArray()
|
||||
);
|
||||
|
||||
WorkflowCheckResult result = service.checkContent(content, WorkflowCheckStage.SAVE, null);
|
||||
Assert.assertFalse(result.isPassed());
|
||||
assertHasCode(result, "LLM_USER_PROMPT_EMPTY");
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证保存阶段接受有效的大模型用户提示词。
|
||||
*/
|
||||
@Test
|
||||
public void testSaveShouldPassNonBlankLlmUserPrompt() throws Exception {
|
||||
WorkflowCheckService service = newService(new HashMap<>());
|
||||
JSONObject llmData = data("大模型");
|
||||
llmData.put("userPrompt", "{{start-1.user_input}}");
|
||||
String content = workflowJson(
|
||||
array(node("llm-1", "llmNode", null, llmData)),
|
||||
new JSONArray()
|
||||
);
|
||||
|
||||
WorkflowCheckResult result = service.checkContent(content, WorkflowCheckStage.SAVE, null);
|
||||
Assert.assertTrue(result.isPassed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreExecuteShouldBlockMissingStartOrEnd() throws Exception {
|
||||
WorkflowCheckService service = newService(new HashMap<>());
|
||||
@@ -453,6 +488,34 @@ public class WorkflowCheckServiceTest {
|
||||
assertHasCode(result, "END_NODE_MISSING");
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证执行前校验拒绝空的大模型用户提示词。
|
||||
*/
|
||||
@Test
|
||||
public void testPreExecuteShouldBlockEmptyLlmUserPrompt() throws Exception {
|
||||
WorkflowCheckService service = newService(new HashMap<>());
|
||||
JSONObject llmData = data("大模型");
|
||||
llmData.put("userPrompt", "");
|
||||
String content = workflowJson(
|
||||
array(
|
||||
node("s1", "startNode", null, data("开始")),
|
||||
node("llm-1", "llmNode", null, llmData),
|
||||
node("e1", "endNode", null, data("结束"))
|
||||
),
|
||||
array(
|
||||
edge("edge-1", "s1", "llm-1"),
|
||||
edge("edge-2", "llm-1", "e1")
|
||||
)
|
||||
);
|
||||
|
||||
WorkflowCheckResult result = service.checkContent(
|
||||
content,
|
||||
WorkflowCheckStage.PRE_EXECUTE,
|
||||
BigInteger.ONE);
|
||||
Assert.assertFalse(result.isPassed());
|
||||
assertHasCode(result, "LLM_USER_PROMPT_EMPTY");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreExecuteShouldPassForSourceOnlySearchDatasetNode() throws Exception {
|
||||
WorkflowCheckService service = newService(new HashMap<>());
|
||||
|
||||
Reference in New Issue
Block a user