Skip to content

Commit 76d050b

Browse files
authored
feat: New condition for determining whether the discriminator is true or not (#2809)
1 parent add9d1b commit 76d050b

File tree

9 files changed

+93
-34
lines changed

9 files changed

+93
-34
lines changed

apps/application/flow/step_node/condition_node/compare/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@
99

1010
from .contain_compare import *
1111
from .equal_compare import *
12-
from .gt_compare import *
1312
from .ge_compare import *
13+
from .gt_compare import *
14+
from .is_not_null_compare import *
15+
from .is_not_true import IsNotTrueCompare
16+
from .is_null_compare import *
17+
from .is_true import IsTrueCompare
1418
from .le_compare import *
15-
from .lt_compare import *
19+
from .len_equal_compare import *
1620
from .len_ge_compare import *
1721
from .len_gt_compare import *
1822
from .len_le_compare import *
1923
from .len_lt_compare import *
20-
from .len_equal_compare import *
21-
from .is_not_null_compare import *
22-
from .is_null_compare import *
24+
from .lt_compare import *
2325
from .not_contain_compare import *
2426

2527
compare_handle_list = [GECompare(), GTCompare(), ContainCompare(), EqualCompare(), LTCompare(), LECompare(),
2628
LenLECompare(), LenGECompare(), LenEqualCompare(), LenGTCompare(), LenLTCompare(),
2729
IsNullCompare(),
28-
IsNotNullCompare(), NotContainCompare()]
30+
IsNotNullCompare(), NotContainCompare(), IsTrueCompare(), IsNotTrueCompare()]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:虎
5+
@file: is_not_true.py
6+
@date:2025/4/7 13:44
7+
@desc:
8+
"""
9+
from typing import List
10+
11+
from application.flow.step_node.condition_node.compare import Compare
12+
13+
14+
class IsNotTrueCompare(Compare):
15+
16+
def support(self, node_id, fields: List[str], source_value, compare, target_value):
17+
if compare == 'is_not_true':
18+
return True
19+
20+
def compare(self, source_value, compare, target_value):
21+
try:
22+
return source_value is False
23+
except Exception as e:
24+
return False
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# coding=utf-8
2+
"""
3+
@project: MaxKB
4+
@Author:虎
5+
@file: IsTrue.py
6+
@date:2025/4/7 13:38
7+
@desc:
8+
"""
9+
from typing import List
10+
11+
from application.flow.step_node.condition_node.compare import Compare
12+
13+
14+
class IsTrueCompare(Compare):
15+
16+
def support(self, node_id, fields: List[str], source_value, compare, target_value):
17+
if compare == 'is_true':
18+
return True
19+
20+
def compare(self, source_value, compare, target_value):
21+
try:
22+
return source_value is True
23+
except Exception as e:
24+
return False

apps/application/flow/step_node/condition_node/impl/base_condition_node.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ def assertion(self, field_list: List[str], compare: str, value):
4040
value = self.workflow_manage.generate_prompt(value)
4141
except Exception as e:
4242
pass
43-
field_value = self.workflow_manage.get_reference_field(field_list[0], field_list[1:])
43+
field_value = None
44+
try:
45+
field_value = self.workflow_manage.get_reference_field(field_list[0], field_list[1:])
46+
except Exception as e:
47+
pass
4448
for compare_handler in compare_handle_list:
4549
if compare_handler.support(field_list[0], field_list[1:], field_value, compare, value):
4650
return compare_handler.compare(field_value, compare, value)

ui/src/locales/lang/en-US/views/application-workflow.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
copyParam: 'Copy Parameters',
2323
debug: 'Run',
2424
exit: 'Exit',
25-
exitSave: 'Save & Exit',
25+
exitSave: 'Save & Exit'
2626
},
2727
tip: {
2828
publicSuccess: 'Published successfully',
@@ -37,7 +37,7 @@ export default {
3737
cannotCopy: 'Cannot be copied',
3838
copyError: 'Node already copied',
3939
paramErrorMessage: 'Parameter already exists: ',
40-
saveMessage: 'Current changes have not been saved. Save before exiting?',
40+
saveMessage: 'Current changes have not been saved. Save before exiting?'
4141
},
4242
delete: {
4343
confirmTitle: 'Confirm to delete this node?',
@@ -229,7 +229,7 @@ export default {
229229
toolParam: 'Tool Params',
230230
mcpServerTip: 'Please enter the JSON format of the MCP server config',
231231
mcpToolTip: 'Please select a tool',
232-
configLabel: 'MCP Server Config (Only supports SSE call method)',
232+
configLabel: 'MCP Server Config (Only supports SSE call method)'
233233
},
234234
imageGenerateNode: {
235235
label: 'Image Generation',
@@ -293,7 +293,9 @@ export default {
293293
len_ge: 'Length greater than or equal to',
294294
len_gt: 'Length greater than',
295295
len_le: 'Length less than or equal to',
296-
len_lt: 'Length less than'
296+
len_lt: 'Length less than',
297+
is_true: 'Is true',
298+
is_not_true: 'Is not true'
297299
},
298300
FileUploadSetting: {}
299301
}

ui/src/locales/lang/zh-CN/views/application-workflow.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
copyParam: '复制参数',
2323
debug: '调试',
2424
exit: '直接退出',
25-
exitSave: '保存并退出',
25+
exitSave: '保存并退出'
2626
},
2727
tip: {
2828
publicSuccess: '发布成功',
@@ -37,7 +37,7 @@ export default {
3737
cannotCopy: '不能被复制',
3838
copyError: '已复制节点',
3939
paramErrorMessage: '参数已存在: ',
40-
saveMessage: '当前的更改尚未保存,是否保存后退出?',
40+
saveMessage: '当前的更改尚未保存,是否保存后退出?'
4141
},
4242
delete: {
4343
confirmTitle: '确定删除该节点?',
@@ -292,7 +292,9 @@ export default {
292292
len_ge: '长度大于等于',
293293
len_gt: '长度大于',
294294
len_le: '长度小于等于',
295-
len_lt: '长度小于'
295+
len_lt: '长度小于',
296+
is_true: '为真',
297+
is_not_true: '不为真'
296298
},
297299
FileUploadSetting: {}
298300
}

ui/src/locales/lang/zh-Hant/views/application-workflow.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
copyParam: '複製參數',
2323
debug: '調試',
2424
exit: '直接退出',
25-
exitSave: '保存並退出',
25+
exitSave: '保存並退出'
2626
},
2727
tip: {
2828
publicSuccess: '發布成功',
@@ -37,7 +37,7 @@ export default {
3737
cannotCopy: '不能被複製',
3838
copyError: '已複製節點',
3939
paramErrorMessage: '參數已存在: ',
40-
saveMessage: '當前修改未保存,是否保存後退出?',
40+
saveMessage: '當前修改未保存,是否保存後退出?'
4141
},
4242
delete: {
4343
confirmTitle: '確定刪除該節點?',
@@ -229,7 +229,7 @@ export default {
229229
toolParam: '工具變數',
230230
mcpServerTip: '請輸入JSON格式的MCP服務器配置',
231231
mcpToolTip: '請選擇工具',
232-
configLabel: 'MCP Server Config (僅支持SSE調用方式)',
232+
configLabel: 'MCP Server Config (僅支持SSE調用方式)'
233233
},
234234
imageGenerateNode: {
235235
label: '圖片生成',
@@ -292,7 +292,9 @@ export default {
292292
len_ge: '長度大於等於',
293293
len_gt: '長度大於',
294294
len_le: '長度小於等於',
295-
len_lt: '長度小於'
295+
len_lt: '長度小於',
296+
is_true: '為真',
297+
is_not_true: '不為真'
296298
},
297299
FileUploadSetting: {}
298300
}

ui/src/workflow/common/data.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export const mcpNode = {
271271
properties: {
272272
stepName: t('views.applicationWorkflow.nodes.mcpNode.label'),
273273
config: {
274-
fields:[
274+
fields: [
275275
{
276276
label: t('common.result'),
277277
value: 'result'
@@ -424,7 +424,9 @@ export const compareList = [
424424
{ value: 'len_ge', label: t('views.applicationWorkflow.compare.len_ge') },
425425
{ value: 'len_gt', label: t('views.applicationWorkflow.compare.len_gt') },
426426
{ value: 'len_le', label: t('views.applicationWorkflow.compare.len_le') },
427-
{ value: 'len_lt', label: t('views.applicationWorkflow.compare.len_lt') }
427+
{ value: 'len_lt', label: t('views.applicationWorkflow.compare.len_lt') },
428+
{ value: 'is_true', label: t('views.applicationWorkflow.compare.is_true') },
429+
{ value: 'is_not_true', label: t('views.applicationWorkflow.compare.is_not_true') }
428430
]
429431

430432
export const nodeDict: any = {
@@ -446,7 +448,7 @@ export const nodeDict: any = {
446448
[WorkflowType.SpeechToTextNode]: speechToTextNode,
447449
[WorkflowType.ImageGenerateNode]: imageGenerateNode,
448450
[WorkflowType.VariableAssignNode]: variableAssignNode,
449-
[WorkflowType.McpNode]: mcpNode,
451+
[WorkflowType.McpNode]: mcpNode
450452
}
451453
export function isWorkFlow(type: string | undefined) {
452454
return type === 'WORK_FLOW'

ui/src/workflow/nodes/condition-node/index.vue

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,8 @@
2525
size="small"
2626
style="width: 60px; margin: 0 8px"
2727
>
28-
<el-option
29-
:label="$t('views.applicationWorkflow.condition.AND')"
30-
value="and"
31-
/>
32-
<el-option
33-
:label="$t('views.applicationWorkflow.condition.OR')"
34-
value="or"
35-
/>
28+
<el-option :label="$t('views.applicationWorkflow.condition.AND')" value="and" />
29+
<el-option :label="$t('views.applicationWorkflow.condition.OR')" value="or" />
3630
</el-select>
3731
<span>{{
3832
$t('views.applicationWorkflow.nodes.conditionNode.conditions.label')
@@ -56,9 +50,7 @@
5650
ref="nodeCascaderRef"
5751
:nodeModel="nodeModel"
5852
class="w-full"
59-
:placeholder="
60-
$t('views.applicationWorkflow.variable.placeholder')
61-
"
53+
:placeholder="$t('views.applicationWorkflow.variable.placeholder')"
6254
v-model="condition.field"
6355
/>
6456
</el-form-item>
@@ -94,7 +86,11 @@
9486
</el-col>
9587
<el-col :span="6">
9688
<el-form-item
97-
v-if="condition.compare !== 'is_null' && condition.compare !== 'is_not_null'"
89+
v-if="
90+
!['is_null', 'is_not_null', 'is_true', 'is_not_true'].includes(
91+
condition.compare
92+
)
93+
"
9894
:prop="'branch.' + index + '.conditions.' + cIndex + '.value'"
9995
:rules="{
10096
required: true,
@@ -137,7 +133,8 @@
137133
</el-card>
138134
</template>
139135
<el-button link type="primary" @click="addBranch">
140-
<el-icon class="mr-4"><Plus /></el-icon> {{ $t('views.applicationWorkflow.nodes.conditionNode.addBranch') }}
136+
<el-icon class="mr-4"><Plus /></el-icon>
137+
{{ $t('views.applicationWorkflow.nodes.conditionNode.addBranch') }}
141138
</el-button>
142139
</el-form>
143140
</NodeContainer>

0 commit comments

Comments
 (0)