浏览代码

ifEsle node add regex match (#8007)

tags/0.8.0
Charlie.Wei 1年前
父节点
当前提交
01858e1caf
没有帐户链接到提交者的电子邮件

+ 1
- 1
api/core/workflow/nodes/if_else/entities.py 查看文件

@@ -12,7 +12,7 @@ class Condition(BaseModel):
variable_selector: list[str]
comparison_operator: Literal[
# for string or array
"contains", "not contains", "start with", "end with", "is", "is not", "empty", "not empty",
"contains", "not contains", "start with", "end with", "is", "is not", "empty", "not empty", "regex match",
# for number
"=", "≠", ">", "<", "≥", "≤", "null", "not null"
]

+ 18
- 0
api/core/workflow/nodes/if_else/if_else_node.py 查看文件

@@ -1,3 +1,4 @@
import re
from collections.abc import Sequence
from typing import Optional, cast

@@ -136,6 +137,8 @@ class IfElseNode(BaseNode):
return self._assert_null(actual_value)
elif comparison_operator == "not null":
return self._assert_not_null(actual_value)
elif comparison_operator == "regex match":
return self._assert_regex_match(actual_value, expected_value)
else:
raise ValueError(f"Invalid comparison operator: {comparison_operator}")

@@ -285,6 +288,21 @@ class IfElseNode(BaseNode):
return True
return False

def _assert_regex_match(self, actual_value: Optional[str], expected_value: str) -> bool:
"""
Assert empty
:param actual_value: actual value
:return:
"""
if actual_value is None:
return False

pattern = re.compile(expected_value)
regex_result = pattern.findall(actual_value)
if len(regex_result) > 0:
return True
return False

def _assert_not_empty(self, actual_value: Optional[str]) -> bool:
"""
Assert not empty

+ 0
- 1
web/app/components/app/configuration/config-var/index.tsx 查看文件

@@ -88,7 +88,6 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
} as InputVar
})()
const updatePromptVariableItem = (payload: InputVar) => {
console.log(payload)
const newPromptVariables = produce(promptVariables, (draft) => {
const { variable, label, type, ...rest } = payload
draft[currIndex] = {

+ 1
- 0
web/app/components/workflow/nodes/if-else/types.ts 查看文件

@@ -28,6 +28,7 @@ export enum ComparisonOperator {
lessThanOrEqual = '≤',
isNull = 'is null',
isNotNull = 'is not null',
regexMatch = 'regex match',
}

export type Condition = {

+ 1
- 0
web/app/components/workflow/nodes/if-else/utils.ts 查看文件

@@ -30,6 +30,7 @@ export const getOperators = (type?: VarType) => {
ComparisonOperator.isNot,
ComparisonOperator.empty,
ComparisonOperator.notEmpty,
ComparisonOperator.regexMatch,
]
case VarType.number:
return [

+ 1
- 0
web/i18n/en-US/workflow.ts 查看文件

@@ -412,6 +412,7 @@ const translation = {
'not empty': 'is not empty',
'null': 'is null',
'not null': 'is not null',
'regex match': 'regex match',
},
enterValue: 'Enter value',
addCondition: 'Add Condition',

+ 1
- 0
web/i18n/zh-Hans/workflow.ts 查看文件

@@ -412,6 +412,7 @@ const translation = {
'not empty': '不为空',
'null': '空',
'not null': '不为空',
'regex match': '正则匹配',
},
enterValue: '输入值',
addCondition: '添加条件',

正在加载...
取消
保存