feat: New condition for determining whether the discriminator is true or not (#2809)

This commit is contained in:
shaohuzhang1 2025-04-07 14:07:30 +08:00 committed by GitHub
parent add9d1bab8
commit 76d050bea4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 93 additions and 34 deletions

View File

@ -9,20 +9,22 @@
from .contain_compare import * from .contain_compare import *
from .equal_compare import * from .equal_compare import *
from .gt_compare import *
from .ge_compare import * from .ge_compare import *
from .gt_compare import *
from .is_not_null_compare import *
from .is_not_true import IsNotTrueCompare
from .is_null_compare import *
from .is_true import IsTrueCompare
from .le_compare import * from .le_compare import *
from .lt_compare import * from .len_equal_compare import *
from .len_ge_compare import * from .len_ge_compare import *
from .len_gt_compare import * from .len_gt_compare import *
from .len_le_compare import * from .len_le_compare import *
from .len_lt_compare import * from .len_lt_compare import *
from .len_equal_compare import * from .lt_compare import *
from .is_not_null_compare import *
from .is_null_compare import *
from .not_contain_compare import * from .not_contain_compare import *
compare_handle_list = [GECompare(), GTCompare(), ContainCompare(), EqualCompare(), LTCompare(), LECompare(), compare_handle_list = [GECompare(), GTCompare(), ContainCompare(), EqualCompare(), LTCompare(), LECompare(),
LenLECompare(), LenGECompare(), LenEqualCompare(), LenGTCompare(), LenLTCompare(), LenLECompare(), LenGECompare(), LenEqualCompare(), LenGTCompare(), LenLTCompare(),
IsNullCompare(), IsNullCompare(),
IsNotNullCompare(), NotContainCompare()] IsNotNullCompare(), NotContainCompare(), IsTrueCompare(), IsNotTrueCompare()]

View File

@ -0,0 +1,24 @@
# coding=utf-8
"""
@project: MaxKB
@Author
@file is_not_true.py
@date2025/4/7 13:44
@desc:
"""
from typing import List
from application.flow.step_node.condition_node.compare import Compare
class IsNotTrueCompare(Compare):
def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'is_not_true':
return True
def compare(self, source_value, compare, target_value):
try:
return source_value is False
except Exception as e:
return False

View File

@ -0,0 +1,24 @@
# coding=utf-8
"""
@project: MaxKB
@Author
@file IsTrue.py
@date2025/4/7 13:38
@desc:
"""
from typing import List
from application.flow.step_node.condition_node.compare import Compare
class IsTrueCompare(Compare):
def support(self, node_id, fields: List[str], source_value, compare, target_value):
if compare == 'is_true':
return True
def compare(self, source_value, compare, target_value):
try:
return source_value is True
except Exception as e:
return False

View File

@ -40,7 +40,11 @@ class BaseConditionNode(IConditionNode):
value = self.workflow_manage.generate_prompt(value) value = self.workflow_manage.generate_prompt(value)
except Exception as e: except Exception as e:
pass pass
field_value = None
try:
field_value = self.workflow_manage.get_reference_field(field_list[0], field_list[1:]) field_value = self.workflow_manage.get_reference_field(field_list[0], field_list[1:])
except Exception as e:
pass
for compare_handler in compare_handle_list: for compare_handler in compare_handle_list:
if compare_handler.support(field_list[0], field_list[1:], field_value, compare, value): if compare_handler.support(field_list[0], field_list[1:], field_value, compare, value):
return compare_handler.compare(field_value, compare, value) return compare_handler.compare(field_value, compare, value)

View File

@ -22,7 +22,7 @@ export default {
copyParam: 'Copy Parameters', copyParam: 'Copy Parameters',
debug: 'Run', debug: 'Run',
exit: 'Exit', exit: 'Exit',
exitSave: 'Save & Exit', exitSave: 'Save & Exit'
}, },
tip: { tip: {
publicSuccess: 'Published successfully', publicSuccess: 'Published successfully',
@ -37,7 +37,7 @@ export default {
cannotCopy: 'Cannot be copied', cannotCopy: 'Cannot be copied',
copyError: 'Node already copied', copyError: 'Node already copied',
paramErrorMessage: 'Parameter already exists: ', paramErrorMessage: 'Parameter already exists: ',
saveMessage: 'Current changes have not been saved. Save before exiting?', saveMessage: 'Current changes have not been saved. Save before exiting?'
}, },
delete: { delete: {
confirmTitle: 'Confirm to delete this node?', confirmTitle: 'Confirm to delete this node?',
@ -229,7 +229,7 @@ export default {
toolParam: 'Tool Params', toolParam: 'Tool Params',
mcpServerTip: 'Please enter the JSON format of the MCP server config', mcpServerTip: 'Please enter the JSON format of the MCP server config',
mcpToolTip: 'Please select a tool', mcpToolTip: 'Please select a tool',
configLabel: 'MCP Server Config (Only supports SSE call method)', configLabel: 'MCP Server Config (Only supports SSE call method)'
}, },
imageGenerateNode: { imageGenerateNode: {
label: 'Image Generation', label: 'Image Generation',
@ -293,7 +293,9 @@ export default {
len_ge: 'Length greater than or equal to', len_ge: 'Length greater than or equal to',
len_gt: 'Length greater than', len_gt: 'Length greater than',
len_le: 'Length less than or equal to', len_le: 'Length less than or equal to',
len_lt: 'Length less than' len_lt: 'Length less than',
is_true: 'Is true',
is_not_true: 'Is not true'
}, },
FileUploadSetting: {} FileUploadSetting: {}
} }

View File

@ -22,7 +22,7 @@ export default {
copyParam: '复制参数', copyParam: '复制参数',
debug: '调试', debug: '调试',
exit: '直接退出', exit: '直接退出',
exitSave: '保存并退出', exitSave: '保存并退出'
}, },
tip: { tip: {
publicSuccess: '发布成功', publicSuccess: '发布成功',
@ -37,7 +37,7 @@ export default {
cannotCopy: '不能被复制', cannotCopy: '不能被复制',
copyError: '已复制节点', copyError: '已复制节点',
paramErrorMessage: '参数已存在: ', paramErrorMessage: '参数已存在: ',
saveMessage: '当前的更改尚未保存,是否保存后退出?', saveMessage: '当前的更改尚未保存,是否保存后退出?'
}, },
delete: { delete: {
confirmTitle: '确定删除该节点?', confirmTitle: '确定删除该节点?',
@ -292,7 +292,9 @@ export default {
len_ge: '长度大于等于', len_ge: '长度大于等于',
len_gt: '长度大于', len_gt: '长度大于',
len_le: '长度小于等于', len_le: '长度小于等于',
len_lt: '长度小于' len_lt: '长度小于',
is_true: '为真',
is_not_true: '不为真'
}, },
FileUploadSetting: {} FileUploadSetting: {}
} }

View File

@ -22,7 +22,7 @@ export default {
copyParam: '複製參數', copyParam: '複製參數',
debug: '調試', debug: '調試',
exit: '直接退出', exit: '直接退出',
exitSave: '保存並退出', exitSave: '保存並退出'
}, },
tip: { tip: {
publicSuccess: '發布成功', publicSuccess: '發布成功',
@ -37,7 +37,7 @@ export default {
cannotCopy: '不能被複製', cannotCopy: '不能被複製',
copyError: '已複製節點', copyError: '已複製節點',
paramErrorMessage: '參數已存在: ', paramErrorMessage: '參數已存在: ',
saveMessage: '當前修改未保存,是否保存後退出?', saveMessage: '當前修改未保存,是否保存後退出?'
}, },
delete: { delete: {
confirmTitle: '確定刪除該節點?', confirmTitle: '確定刪除該節點?',
@ -229,7 +229,7 @@ export default {
toolParam: '工具變數', toolParam: '工具變數',
mcpServerTip: '請輸入JSON格式的MCP服務器配置', mcpServerTip: '請輸入JSON格式的MCP服務器配置',
mcpToolTip: '請選擇工具', mcpToolTip: '請選擇工具',
configLabel: 'MCP Server Config (僅支持SSE調用方式)', configLabel: 'MCP Server Config (僅支持SSE調用方式)'
}, },
imageGenerateNode: { imageGenerateNode: {
label: '圖片生成', label: '圖片生成',
@ -292,7 +292,9 @@ export default {
len_ge: '長度大於等於', len_ge: '長度大於等於',
len_gt: '長度大於', len_gt: '長度大於',
len_le: '長度小於等於', len_le: '長度小於等於',
len_lt: '長度小於' len_lt: '長度小於',
is_true: '為真',
is_not_true: '不為真'
}, },
FileUploadSetting: {} FileUploadSetting: {}
} }

View File

@ -271,7 +271,7 @@ export const mcpNode = {
properties: { properties: {
stepName: t('views.applicationWorkflow.nodes.mcpNode.label'), stepName: t('views.applicationWorkflow.nodes.mcpNode.label'),
config: { config: {
fields:[ fields: [
{ {
label: t('common.result'), label: t('common.result'),
value: 'result' value: 'result'
@ -424,7 +424,9 @@ export const compareList = [
{ value: 'len_ge', label: t('views.applicationWorkflow.compare.len_ge') }, { value: 'len_ge', label: t('views.applicationWorkflow.compare.len_ge') },
{ value: 'len_gt', label: t('views.applicationWorkflow.compare.len_gt') }, { value: 'len_gt', label: t('views.applicationWorkflow.compare.len_gt') },
{ value: 'len_le', label: t('views.applicationWorkflow.compare.len_le') }, { value: 'len_le', label: t('views.applicationWorkflow.compare.len_le') },
{ value: 'len_lt', label: t('views.applicationWorkflow.compare.len_lt') } { value: 'len_lt', label: t('views.applicationWorkflow.compare.len_lt') },
{ value: 'is_true', label: t('views.applicationWorkflow.compare.is_true') },
{ value: 'is_not_true', label: t('views.applicationWorkflow.compare.is_not_true') }
] ]
export const nodeDict: any = { export const nodeDict: any = {
@ -446,7 +448,7 @@ export const nodeDict: any = {
[WorkflowType.SpeechToTextNode]: speechToTextNode, [WorkflowType.SpeechToTextNode]: speechToTextNode,
[WorkflowType.ImageGenerateNode]: imageGenerateNode, [WorkflowType.ImageGenerateNode]: imageGenerateNode,
[WorkflowType.VariableAssignNode]: variableAssignNode, [WorkflowType.VariableAssignNode]: variableAssignNode,
[WorkflowType.McpNode]: mcpNode, [WorkflowType.McpNode]: mcpNode
} }
export function isWorkFlow(type: string | undefined) { export function isWorkFlow(type: string | undefined) {
return type === 'WORK_FLOW' return type === 'WORK_FLOW'

View File

@ -25,14 +25,8 @@
size="small" size="small"
style="width: 60px; margin: 0 8px" style="width: 60px; margin: 0 8px"
> >
<el-option <el-option :label="$t('views.applicationWorkflow.condition.AND')" value="and" />
:label="$t('views.applicationWorkflow.condition.AND')" <el-option :label="$t('views.applicationWorkflow.condition.OR')" value="or" />
value="and"
/>
<el-option
:label="$t('views.applicationWorkflow.condition.OR')"
value="or"
/>
</el-select> </el-select>
<span>{{ <span>{{
$t('views.applicationWorkflow.nodes.conditionNode.conditions.label') $t('views.applicationWorkflow.nodes.conditionNode.conditions.label')
@ -56,9 +50,7 @@
ref="nodeCascaderRef" ref="nodeCascaderRef"
:nodeModel="nodeModel" :nodeModel="nodeModel"
class="w-full" class="w-full"
:placeholder=" :placeholder="$t('views.applicationWorkflow.variable.placeholder')"
$t('views.applicationWorkflow.variable.placeholder')
"
v-model="condition.field" v-model="condition.field"
/> />
</el-form-item> </el-form-item>
@ -94,7 +86,11 @@
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
<el-form-item <el-form-item
v-if="condition.compare !== 'is_null' && condition.compare !== 'is_not_null'" v-if="
!['is_null', 'is_not_null', 'is_true', 'is_not_true'].includes(
condition.compare
)
"
:prop="'branch.' + index + '.conditions.' + cIndex + '.value'" :prop="'branch.' + index + '.conditions.' + cIndex + '.value'"
:rules="{ :rules="{
required: true, required: true,
@ -137,7 +133,8 @@
</el-card> </el-card>
</template> </template>
<el-button link type="primary" @click="addBranch"> <el-button link type="primary" @click="addBranch">
<el-icon class="mr-4"><Plus /></el-icon> {{ $t('views.applicationWorkflow.nodes.conditionNode.addBranch') }} <el-icon class="mr-4"><Plus /></el-icon>
{{ $t('views.applicationWorkflow.nodes.conditionNode.addBranch') }}
</el-button> </el-button>
</el-form> </el-form>
</NodeContainer> </NodeContainer>