From 0e68195552f113bef24080e4dd236b1fe4e2c90b Mon Sep 17 00:00:00 2001 From: GuanMu Date: Thu, 12 Jun 2025 02:12:26 +0000 Subject: [PATCH] fix: Add output fields to all answer nodes --- .../core/workflow/graph_engine/test_graph.py | 20 ++++++------ .../graph_engine/test_graph_engine.py | 18 +++++++---- .../core/workflow/nodes/answer/test_answer.py | 1 + .../test_answer_stream_generate_router.py | 4 +-- .../answer/test_answer_stream_processor.py | 4 +-- .../nodes/iteration/test_iteration.py | 17 ++++++---- .../core/workflow/nodes/test_answer.py | 2 ++ .../workflow/nodes/test_continue_on_error.py | 32 +++++++++---------- .../core/workflow/nodes/test_retry.py | 4 +-- 9 files changed, 57 insertions(+), 45 deletions(-) diff --git a/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py b/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py index 13ba11016a..8a7bafec1f 100644 --- a/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py +++ b/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py @@ -43,7 +43,7 @@ def test_init(): "id": "llm", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer", }, { @@ -57,7 +57,7 @@ def test_init(): "id": "http", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer2", }, ], @@ -126,7 +126,7 @@ def test__init_iteration_graph(): "id": "llm", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer", }, { @@ -148,7 +148,7 @@ def test__init_iteration_graph(): "parentId": "iteration", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer-in-iteration", "parentId": "iteration", }, @@ -235,7 +235,7 @@ def test_parallels_graph(): "id": "llm3", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer", }, ], @@ -310,7 +310,7 @@ def test_parallels_graph2(): "id": "llm3", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer", }, ], @@ -373,7 +373,7 @@ def test_parallels_graph3(): "id": "llm3", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer", }, ], @@ -480,7 +480,7 @@ def test_parallels_graph4(): "id": "code3", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer", }, ], @@ -606,7 +606,7 @@ def test_parallels_graph5(): "id": "code3", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer", }, { @@ -745,7 +745,7 @@ def test_parallels_graph6(): "id": "code3", }, { - "data": {"type": "answer", "title": "answer", "answer": "1"}, + "data": {"type": "answer", "title": "answer", "answer": "1", "outputs": []}, "id": "answer", }, ], diff --git a/api/tests/unit_tests/core/workflow/graph_engine/test_graph_engine.py b/api/tests/unit_tests/core/workflow/graph_engine/test_graph_engine.py index 7535ec4866..e8d8efb97c 100644 --- a/api/tests/unit_tests/core/workflow/graph_engine/test_graph_engine.py +++ b/api/tests/unit_tests/core/workflow/graph_engine/test_graph_engine.py @@ -267,21 +267,21 @@ def test_run_parallel_in_chatflow(mock_close, mock_remove): ], "nodes": [ {"data": {"type": "start", "title": "start"}, "id": "start"}, - {"data": {"type": "answer", "title": "answer1", "answer": "1"}, "id": "answer1"}, + {"data": {"type": "answer", "title": "answer1", "answer": "1", "outputs": []}, "id": "answer1"}, { - "data": {"type": "answer", "title": "answer2", "answer": "2"}, + "data": {"type": "answer", "title": "answer2", "answer": "2", "outputs": []}, "id": "answer2", }, { - "data": {"type": "answer", "title": "answer3", "answer": "3"}, + "data": {"type": "answer", "title": "answer3", "answer": "3", "outputs": []}, "id": "answer3", }, { - "data": {"type": "answer", "title": "answer4", "answer": "4"}, + "data": {"type": "answer", "title": "answer4", "answer": "4", "outputs": []}, "id": "answer4", }, { - "data": {"type": "answer", "title": "answer5", "answer": "5"}, + "data": {"type": "answer", "title": "answer5", "answer": "5", "outputs": []}, "id": "answer5", }, ], @@ -398,7 +398,7 @@ def test_run_branch(mock_close, mock_remove): "id": "start", }, { - "data": {"answer": "1 {{#start.uid#}}", "title": "Answer", "type": "answer", "variables": []}, + "data": {"answer": "1 {{#start.uid#}}", "title": "Answer", "type": "answer", "variables": [], "outputs": []}, "id": "answer-1", }, { @@ -453,6 +453,7 @@ def test_run_branch(mock_close, mock_remove): "answer": "2", "title": "Answer 2", "type": "answer", + "outputs": [], }, "id": "answer-2", }, @@ -461,6 +462,7 @@ def test_run_branch(mock_close, mock_remove): "answer": "3", "title": "Answer 3", "type": "answer", + "outputs": [], }, "id": "answer-3", }, @@ -701,6 +703,7 @@ def test_condition_parallel_correct_output(mock_close, mock_remove, app): "title": "answer 2", "type": "answer", "variables": [], + "outputs": [], }, "height": 105, "id": "1742382531085", @@ -720,6 +723,7 @@ def test_condition_parallel_correct_output(mock_close, mock_remove, app): "title": "answer 3", "type": "answer", "variables": [], + "outputs": [], }, "height": 105, "id": "1742382534798", @@ -739,6 +743,7 @@ def test_condition_parallel_correct_output(mock_close, mock_remove, app): "title": "answer 4", "type": "answer", "variables": [], + "outputs": [], }, "height": 105, "id": "1742382538517", @@ -758,6 +763,7 @@ def test_condition_parallel_correct_output(mock_close, mock_remove, app): "title": "Answer 5", "type": "answer", "variables": [], + "outputs": [], }, "height": 105, "id": "1742434464898", diff --git a/api/tests/unit_tests/core/workflow/nodes/answer/test_answer.py b/api/tests/unit_tests/core/workflow/nodes/answer/test_answer.py index b7f78d91fa..860bc29455 100644 --- a/api/tests/unit_tests/core/workflow/nodes/answer/test_answer.py +++ b/api/tests/unit_tests/core/workflow/nodes/answer/test_answer.py @@ -69,6 +69,7 @@ def test_execute_answer(): "title": "123", "type": "answer", "answer": "Today's weather is {{#start.weather#}}\n{{#llm.text#}}\n{{img}}\nFin.", + "outputs": [], }, }, ) diff --git a/api/tests/unit_tests/core/workflow/nodes/answer/test_answer_stream_generate_router.py b/api/tests/unit_tests/core/workflow/nodes/answer/test_answer_stream_generate_router.py index bce87536d8..76b8f596e7 100644 --- a/api/tests/unit_tests/core/workflow/nodes/answer/test_answer_stream_generate_router.py +++ b/api/tests/unit_tests/core/workflow/nodes/answer/test_answer_stream_generate_router.py @@ -89,11 +89,11 @@ def test_init(): "id": "llm5", }, { - "data": {"type": "answer", "title": "answer", "answer": "1{{#llm2.text#}}2"}, + "data": {"type": "answer", "title": "answer", "answer": "1{{#llm2.text#}}2", "outputs": []}, "id": "answer", }, { - "data": {"type": "answer", "title": "answer2", "answer": "1{{#llm3.text#}}2"}, + "data": {"type": "answer", "title": "answer2", "answer": "1{{#llm3.text#}}2", "outputs": []}, "id": "answer2", }, ], diff --git a/api/tests/unit_tests/core/workflow/nodes/answer/test_answer_stream_processor.py b/api/tests/unit_tests/core/workflow/nodes/answer/test_answer_stream_processor.py index c3a3818655..19147fcde7 100644 --- a/api/tests/unit_tests/core/workflow/nodes/answer/test_answer_stream_processor.py +++ b/api/tests/unit_tests/core/workflow/nodes/answer/test_answer_stream_processor.py @@ -167,11 +167,11 @@ def test_process(): "id": "llm5", }, { - "data": {"type": "answer", "title": "answer", "answer": "a{{#llm2.text#}}b"}, + "data": {"type": "answer", "title": "answer", "answer": "a{{#llm2.text#}}b", "outputs": []}, "id": "answer", }, { - "data": {"type": "answer", "title": "answer2", "answer": "c{{#llm3.text#}}d"}, + "data": {"type": "answer", "title": "answer2", "answer": "c{{#llm3.text#}}d", "outputs": []}, "id": "answer2", }, ], diff --git a/api/tests/unit_tests/core/workflow/nodes/iteration/test_iteration.py b/api/tests/unit_tests/core/workflow/nodes/iteration/test_iteration.py index 6d854c950d..7db224ba3f 100644 --- a/api/tests/unit_tests/core/workflow/nodes/iteration/test_iteration.py +++ b/api/tests/unit_tests/core/workflow/nodes/iteration/test_iteration.py @@ -74,6 +74,7 @@ def test_run(): "iteration_id": "iteration-1", "title": "answer 2", "type": "answer", + "outputs": [], }, "id": "answer-2", }, @@ -88,7 +89,7 @@ def test_run(): "id": "tt", }, { - "data": {"answer": "{{#iteration-1.output#}}88888", "title": "answer 3", "type": "answer"}, + "data": {"answer": "{{#iteration-1.output#}}88888", "title": "answer 3", "type": "answer", "outputs": []}, "id": "answer-3", }, { @@ -109,7 +110,7 @@ def test_run(): "id": "if-else", }, { - "data": {"answer": "no hi", "iteration_id": "iteration-1", "title": "answer 4", "type": "answer"}, + "data": {"answer": "no hi", "iteration_id": "iteration-1", "title": "answer 4", "type": "answer", "outputs": []}, "id": "answer-4", }, { @@ -273,6 +274,7 @@ def test_run_parallel(): "iteration_id": "iteration-1", "title": "answer 2", "type": "answer", + "outputs": [], }, "id": "answer-2", }, @@ -305,7 +307,7 @@ def test_run_parallel(): "id": "tt-2", }, { - "data": {"answer": "{{#iteration-1.output#}}88888", "title": "answer 3", "type": "answer"}, + "data": {"answer": "{{#iteration-1.output#}}88888", "title": "answer 3", "type": "answer", "outputs": []}, "id": "answer-3", }, { @@ -326,7 +328,7 @@ def test_run_parallel(): "id": "if-else", }, { - "data": {"answer": "no hi", "iteration_id": "iteration-1", "title": "answer 4", "type": "answer"}, + "data": {"answer": "no hi", "iteration_id": "iteration-1", "title": "answer 4", "type": "answer", "outputs": []}, "id": "answer-4", }, { @@ -489,6 +491,7 @@ def test_iteration_run_in_parallel_mode(): "iteration_id": "iteration-1", "title": "answer 2", "type": "answer", + "outputs": [], }, "id": "answer-2", }, @@ -521,7 +524,7 @@ def test_iteration_run_in_parallel_mode(): "id": "tt-2", }, { - "data": {"answer": "{{#iteration-1.output#}}88888", "title": "answer 3", "type": "answer"}, + "data": {"answer": "{{#iteration-1.output#}}88888", "title": "answer 3", "type": "answer", "outputs": []}, "id": "answer-3", }, { @@ -542,7 +545,7 @@ def test_iteration_run_in_parallel_mode(): "id": "if-else", }, { - "data": {"answer": "no hi", "iteration_id": "iteration-1", "title": "answer 4", "type": "answer"}, + "data": {"answer": "no hi", "iteration_id": "iteration-1", "title": "answer 4", "type": "answer", "outputs": []}, "id": "answer-4", }, { @@ -741,7 +744,7 @@ def test_iteration_run_error_handle(): "id": "tt2", }, { - "data": {"answer": "{{#iteration-1.output#}}88888", "title": "answer 3", "type": "answer"}, + "data": {"answer": "{{#iteration-1.output#}}88888", "title": "answer 3", "type": "answer", "outputs": []}, "id": "answer-3", }, { diff --git a/api/tests/unit_tests/core/workflow/nodes/test_answer.py b/api/tests/unit_tests/core/workflow/nodes/test_answer.py index abc822e98b..2b7a3c8ea7 100644 --- a/api/tests/unit_tests/core/workflow/nodes/test_answer.py +++ b/api/tests/unit_tests/core/workflow/nodes/test_answer.py @@ -31,6 +31,7 @@ def test_execute_answer(): "title": "123", "type": "answer", "answer": "Today's weather is {{#start.weather#}}\n{{#llm.text#}}\n{{img}}\nFin.", + "outputs": [], }, "id": "answer", }, @@ -72,6 +73,7 @@ def test_execute_answer(): "title": "123", "type": "answer", "answer": "Today's weather is {{#start.weather#}}\n{{#llm.text#}}\n{{img}}\nFin.", + "outputs": [], }, }, ) diff --git a/api/tests/unit_tests/core/workflow/nodes/test_continue_on_error.py b/api/tests/unit_tests/core/workflow/nodes/test_continue_on_error.py index ff60d5974b..7802e88028 100644 --- a/api/tests/unit_tests/core/workflow/nodes/test_continue_on_error.py +++ b/api/tests/unit_tests/core/workflow/nodes/test_continue_on_error.py @@ -239,7 +239,7 @@ def test_code_default_value_continue_on_error(): "edges": DEFAULT_VALUE_EDGE, "nodes": [ {"data": {"title": "start", "type": "start", "variables": []}, "id": "start"}, - {"data": {"title": "answer", "type": "answer", "answer": "{{#node.result#}}"}, "id": "answer"}, + {"data": {"title": "answer", "type": "answer", "answer": "{{#node.result#}}", "outputs": []}, "id": "answer"}, ContinueOnErrorTestHelper.get_code_node( error_code, "default-value", [{"key": "result", "type": "number", "value": 132123}] ), @@ -266,11 +266,11 @@ def test_code_fail_branch_continue_on_error(): "nodes": [ {"data": {"title": "Start", "type": "start", "variables": []}, "id": "start"}, { - "data": {"title": "success", "type": "answer", "answer": "node node run successfully"}, + "data": {"title": "success", "type": "answer", "answer": "node node run successfully", "outputs": []}, "id": "success", }, { - "data": {"title": "error", "type": "answer", "answer": "node node run failed"}, + "data": {"title": "error", "type": "answer", "answer": "node node run failed", "outputs": []}, "id": "error", }, ContinueOnErrorTestHelper.get_code_node(error_code), @@ -292,7 +292,7 @@ def test_http_node_default_value_continue_on_error(): "edges": DEFAULT_VALUE_EDGE, "nodes": [ {"data": {"title": "start", "type": "start", "variables": []}, "id": "start"}, - {"data": {"title": "answer", "type": "answer", "answer": "{{#node.response#}}"}, "id": "answer"}, + {"data": {"title": "answer", "type": "answer", "answer": "{{#node.response#}}", "outputs": []}, "id": "answer"}, ContinueOnErrorTestHelper.get_http_node( "default-value", [{"key": "response", "type": "string", "value": "http node got error response"}] ), @@ -317,11 +317,11 @@ def test_http_node_fail_branch_continue_on_error(): "nodes": [ {"data": {"title": "Start", "type": "start", "variables": []}, "id": "start"}, { - "data": {"title": "success", "type": "answer", "answer": "HTTP request successful"}, + "data": {"title": "success", "type": "answer", "answer": "HTTP request successful", "outputs": []}, "id": "success", }, { - "data": {"title": "error", "type": "answer", "answer": "HTTP request failed"}, + "data": {"title": "error", "type": "answer", "answer": "HTTP request failed", "outputs": []}, "id": "error", }, ContinueOnErrorTestHelper.get_http_node(), @@ -395,7 +395,7 @@ def test_llm_node_default_value_continue_on_error(): "edges": DEFAULT_VALUE_EDGE, "nodes": [ {"data": {"title": "start", "type": "start", "variables": []}, "id": "start"}, - {"data": {"title": "answer", "type": "answer", "answer": "{{#node.answer#}}"}, "id": "answer"}, + {"data": {"title": "answer", "type": "answer", "answer": "{{#node.answer#}}", "outputs": []}, "id": "answer"}, ContinueOnErrorTestHelper.get_llm_node( "default-value", [{"key": "answer", "type": "string", "value": "default LLM response"}] ), @@ -419,11 +419,11 @@ def test_llm_node_fail_branch_continue_on_error(): "nodes": [ {"data": {"title": "Start", "type": "start", "variables": []}, "id": "start"}, { - "data": {"title": "success", "type": "answer", "answer": "LLM request successful"}, + "data": {"title": "success", "type": "answer", "answer": "LLM request successful", "outputs": []}, "id": "success", }, { - "data": {"title": "error", "type": "answer", "answer": "LLM request failed"}, + "data": {"title": "error", "type": "answer", "answer": "LLM request failed", "outputs": []}, "id": "error", }, ContinueOnErrorTestHelper.get_llm_node(), @@ -447,11 +447,11 @@ def test_status_code_error_http_node_fail_branch_continue_on_error(): "nodes": [ {"data": {"title": "Start", "type": "start", "variables": []}, "id": "start"}, { - "data": {"title": "success", "type": "answer", "answer": "http execute successful"}, + "data": {"title": "success", "type": "answer", "answer": "http execute successful", "outputs": []}, "id": "success", }, { - "data": {"title": "error", "type": "answer", "answer": "http execute failed"}, + "data": {"title": "error", "type": "answer", "answer": "http execute failed", "outputs": []}, "id": "error", }, ContinueOnErrorTestHelper.get_error_status_code_http_node(), @@ -474,11 +474,11 @@ def test_variable_pool_error_type_variable(): "nodes": [ {"data": {"title": "Start", "type": "start", "variables": []}, "id": "start"}, { - "data": {"title": "success", "type": "answer", "answer": "http execute successful"}, + "data": {"title": "success", "type": "answer", "answer": "http execute successful", "outputs": []}, "id": "success", }, { - "data": {"title": "error", "type": "answer", "answer": "http execute failed"}, + "data": {"title": "error", "type": "answer", "answer": "http execute failed", "outputs": []}, "id": "error", }, ContinueOnErrorTestHelper.get_error_status_code_http_node(), @@ -499,7 +499,7 @@ def test_no_node_in_fail_branch_continue_on_error(): "edges": FAIL_BRANCH_EDGES[:-1], "nodes": [ {"data": {"title": "Start", "type": "start", "variables": []}, "id": "start"}, - {"data": {"title": "success", "type": "answer", "answer": "HTTP request successful"}, "id": "success"}, + {"data": {"title": "success", "type": "answer", "answer": "HTTP request successful", "outputs": []}, "id": "success"}, ContinueOnErrorTestHelper.get_http_node(), ], } @@ -519,11 +519,11 @@ def test_stream_output_with_fail_branch_continue_on_error(): "nodes": [ {"data": {"title": "Start", "type": "start", "variables": []}, "id": "start"}, { - "data": {"title": "success", "type": "answer", "answer": "LLM request successful"}, + "data": {"title": "success", "type": "answer", "answer": "LLM request successful", "outputs": []}, "id": "success", }, { - "data": {"title": "error", "type": "answer", "answer": "{{#node.text#}}"}, + "data": {"title": "error", "type": "answer", "answer": "{{#node.text#}}", "outputs": []}, "id": "error", }, ContinueOnErrorTestHelper.get_llm_node(), diff --git a/api/tests/unit_tests/core/workflow/nodes/test_retry.py b/api/tests/unit_tests/core/workflow/nodes/test_retry.py index 57d3b203b9..40ac03188d 100644 --- a/api/tests/unit_tests/core/workflow/nodes/test_retry.py +++ b/api/tests/unit_tests/core/workflow/nodes/test_retry.py @@ -27,7 +27,7 @@ def test_retry_default_value_partial_success(): "edges": DEFAULT_VALUE_EDGE, "nodes": [ {"data": {"title": "start", "type": "start", "variables": []}, "id": "start"}, - {"data": {"title": "answer", "type": "answer", "answer": "{{#node.result#}}"}, "id": "answer"}, + {"data": {"title": "answer", "type": "answer", "answer": "{{#node.result#}}", "outputs": []}, "id": "answer"}, ContinueOnErrorTestHelper.get_http_node( "default-value", [{"key": "result", "type": "string", "value": "http node got error response"}], @@ -50,7 +50,7 @@ def test_retry_failed(): "edges": DEFAULT_VALUE_EDGE, "nodes": [ {"data": {"title": "start", "type": "start", "variables": []}, "id": "start"}, - {"data": {"title": "answer", "type": "answer", "answer": "{{#node.result#}}"}, "id": "answer"}, + {"data": {"title": "answer", "type": "answer", "answer": "{{#node.result#}}", "outputs": []}, "id": "answer"}, ContinueOnErrorTestHelper.get_http_node( None, None,