Skip to content

Commit a90ce01

Browse files
feat: Variable assign supports set to null (#4965)
* feat: `Variable assign` supports set to `null`
1 parent 1ba68c5 commit a90ce01

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

apps/application/flow/step_node/variable_assign_node/impl/base_variable_assign_node.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,44 @@ def handle(self, variable, evaluation):
6060
val = variable['value']
6161
evaluation(variable, val)
6262
result['output_value'] = val
63-
else:
63+
elif variable['source'] == 'referencing':
6464
reference = self.get_reference_content(variable['reference'])
6565
evaluation(variable, reference)
6666
result['output_value'] = reference
67+
else:
68+
val = None
69+
evaluation(variable, val)
70+
result['output_value'] = val
71+
72+
# 获取输入输出值的类型,用于显示在执行详情页面中
73+
result['input_type'] = type(result.get('input_value')).__name__ if result.get('input_value') is not None else 'null'
74+
result['output_type'] = type(result.get('output_value')).__name__ if result.get('output_value') is not None else 'null'
75+
6776
return result
6877

6978
def execute(self, variable_list, **kwargs) -> NodeResult:
70-
#
7179
result_list = []
72-
is_chat = False
80+
contains_chat_variable = False
7381
for variable in variable_list:
74-
if 'fields' not in variable:
82+
if not variable.get('fields'):
7583
continue
76-
if 'global' == variable['fields'][0]:
84+
85+
field0 = variable['fields'][0]
86+
if 'global' == field0:
7787
result = self.handle(variable, self.global_evaluation)
7888
result_list.append(result)
79-
if 'chat' == variable['fields'][0]:
89+
elif 'chat' == field0:
8090
result = self.handle(variable, self.chat_evaluation)
8191
result_list.append(result)
82-
is_chat = True
83-
if 'loop' == variable['fields'][0]:
92+
contains_chat_variable = True
93+
elif 'loop' == field0:
8494
result = self.handle(variable, self.loop_evaluation)
8595
result_list.append(result)
86-
if 'output' == variable['fields'][0]:
96+
elif 'output' == field0:
8797
result = self.handle(variable, self.out_evaluation)
8898
result_list.append(result)
89-
if is_chat:
99+
100+
if contains_chat_variable:
90101
from application.flow.loop_workflow_manage import LoopWorkflowManage
91102
if isinstance(self.workflow_manage, LoopWorkflowManage):
92103
self.workflow_manage.parentWorkflowManage.get_chat_info().set_chat_variable(

ui/src/components/execution-detail-card/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@
882882
</h5>
883883
<div class="p-8-12 border-t-dashed lighter">
884884
<div v-for="(f, i) in data.result_list" :key="i" class="mb-8">
885-
<span class="color-secondary">{{ f.name }}:</span> {{ f.input_value }}
885+
<span class="color-secondary">{{ f.name }} ({{ f.input_type }}):</span> {{ f.input_value }}
886886
</div>
887887
</div>
888888
</div>
@@ -892,7 +892,7 @@
892892
</h5>
893893
<div class="p-8-12 border-t-dashed lighter">
894894
<div v-for="(f, i) in data.result_list" :key="i" class="mb-8">
895-
<span class="color-secondary">{{ f.name }}:</span> {{ f.output_value }}
895+
<span class="color-secondary">{{ f.name }} ({{ f.output_type }}):</span> {{ f.output_value }}
896896
</div>
897897
</div>
898898
</div>

ui/src/workflow/nodes/variable-assign-node/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<el-select :teleported="false" v-model="item.source" size="small" style="width: 85px">
4646
<el-option :label="$t('workflow.variable.Referencing')" value="referencing" />
4747
<el-option :label="$t('common.custom')" value="custom" />
48+
<el-option label="null" value="null" />
4849
</el-select>
4950
</div>
5051

@@ -142,7 +143,7 @@
142143
</el-select>
143144
</el-form-item>
144145
</div>
145-
<el-form-item v-else>
146+
<el-form-item v-else-if="item.source === 'referencing'">
146147
<NodeCascader
147148
ref="nodeCascaderRef2"
148149
:nodeModel="nodeModel"

0 commit comments

Comments
 (0)