fix: Simplify the formatting of output variables, improve code readability; update test cases to verify the correctness of different output configurations.

pull/20921/head
GuanMu 10 months ago
parent 81027f6077
commit ea3a99efcd

@ -198,9 +198,11 @@ class GraphEngine:
].strip() ].strip()
# Only save the user-defined output variables, not the entire node output # Only save the user-defined output variables, not the entire node output
if (item.route_node_state.node_run_result if (
item.route_node_state.node_run_result
and item.route_node_state.node_run_result.outputs and item.route_node_state.node_run_result.outputs
and "outputs" in item.route_node_state.node_run_result.outputs): and "outputs" in item.route_node_state.node_run_result.outputs
):
user_outputs = item.route_node_state.node_run_result.outputs.get("outputs", {}) user_outputs = item.route_node_state.node_run_result.outputs.get("outputs", {})
self.graph_runtime_state.outputs.update(user_outputs) self.graph_runtime_state.outputs.update(user_outputs)
except Exception as e: except Exception as e:

@ -102,16 +102,8 @@ def test_execute_answer_with_outputs():
"type": "answer", "type": "answer",
"answer": "Weather: {{#start.weather#}}, Score: {{#start.score#}}", "answer": "Weather: {{#start.weather#}}, Score: {{#start.score#}}",
"outputs": [ "outputs": [
{ {"variable": "confidence", "type": "number", "value_selector": ["start", "score"]},
"variable": "confidence", {"variable": "status", "type": "string", "value_selector": ["start", "weather"]},
"type": "number",
"value_selector": ["start", "score"]
},
{
"variable": "status",
"type": "string",
"value_selector": ["start", "weather"]
}
], ],
}, },
"id": "answer", "id": "answer",
@ -155,16 +147,8 @@ def test_execute_answer_with_outputs():
"type": "answer", "type": "answer",
"answer": "Weather: {{#start.weather#}}, Score: {{#start.score#}}", "answer": "Weather: {{#start.weather#}}, Score: {{#start.score#}}",
"outputs": [ "outputs": [
{ {"variable": "confidence", "type": "number", "value_selector": ["start", "score"]},
"variable": "confidence", {"variable": "status", "type": "string", "value_selector": ["start", "weather"]},
"type": "number",
"value_selector": ["start", "score"]
},
{
"variable": "status",
"type": "string",
"value_selector": ["start", "weather"]
}
], ],
}, },
}, },
@ -205,16 +189,8 @@ def test_execute_answer_with_complex_outputs():
"type": "answer", "type": "answer",
"answer": "Analysis complete", "answer": "Analysis complete",
"outputs": [ "outputs": [
{ {"variable": "scores", "type": "array[number]", "value_selector": ["start", "score_list"]},
"variable": "scores", {"variable": "metadata", "type": "object", "value_selector": ["start", "meta_info"]},
"type": "array[number]",
"value_selector": ["start", "score_list"]
},
{
"variable": "metadata",
"type": "object",
"value_selector": ["start", "meta_info"]
}
], ],
}, },
"id": "answer", "id": "answer",
@ -258,16 +234,8 @@ def test_execute_answer_with_complex_outputs():
"type": "answer", "type": "answer",
"answer": "Analysis complete", "answer": "Analysis complete",
"outputs": [ "outputs": [
{ {"variable": "scores", "type": "array[number]", "value_selector": ["start", "score_list"]},
"variable": "scores", {"variable": "metadata", "type": "object", "value_selector": ["start", "meta_info"]},
"type": "array[number]",
"value_selector": ["start", "score_list"]
},
{
"variable": "metadata",
"type": "object",
"value_selector": ["start", "meta_info"]
}
], ],
}, },
}, },
@ -383,11 +351,7 @@ def test_execute_answer_outputs_variable_not_found():
"type": "answer", "type": "answer",
"answer": "Test answer", "answer": "Test answer",
"outputs": [ "outputs": [
{ {"variable": "missing_var", "type": "string", "value_selector": ["start", "non_existent"]}
"variable": "missing_var",
"type": "string",
"value_selector": ["start", "non_existent"]
}
], ],
}, },
"id": "answer", "id": "answer",
@ -428,13 +392,7 @@ def test_execute_answer_outputs_variable_not_found():
"title": "Missing variable", "title": "Missing variable",
"type": "answer", "type": "answer",
"answer": "Test answer", "answer": "Test answer",
"outputs": [ "outputs": [{"variable": "missing_var", "type": "string", "value_selector": ["start", "non_existent"]}],
{
"variable": "missing_var",
"type": "string",
"value_selector": ["start", "non_existent"]
}
],
}, },
}, },
) )

Loading…
Cancel
Save