ifEsle node add regex match (#8007)
This commit is contained in:
parent
2060db8e11
commit
01858e1caf
@ -12,7 +12,7 @@ class Condition(BaseModel):
|
|||||||
variable_selector: list[str]
|
variable_selector: list[str]
|
||||||
comparison_operator: Literal[
|
comparison_operator: Literal[
|
||||||
# for string or array
|
# 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
|
# for number
|
||||||
"=", "≠", ">", "<", "≥", "≤", "null", "not null"
|
"=", "≠", ">", "<", "≥", "≤", "null", "not null"
|
||||||
]
|
]
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from typing import Optional, cast
|
from typing import Optional, cast
|
||||||
|
|
||||||
@ -136,6 +137,8 @@ class IfElseNode(BaseNode):
|
|||||||
return self._assert_null(actual_value)
|
return self._assert_null(actual_value)
|
||||||
elif comparison_operator == "not null":
|
elif comparison_operator == "not null":
|
||||||
return self._assert_not_null(actual_value)
|
return self._assert_not_null(actual_value)
|
||||||
|
elif comparison_operator == "regex match":
|
||||||
|
return self._assert_regex_match(actual_value, expected_value)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid comparison operator: {comparison_operator}")
|
raise ValueError(f"Invalid comparison operator: {comparison_operator}")
|
||||||
|
|
||||||
@ -285,6 +288,21 @@ class IfElseNode(BaseNode):
|
|||||||
return True
|
return True
|
||||||
return False
|
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:
|
def _assert_not_empty(self, actual_value: Optional[str]) -> bool:
|
||||||
"""
|
"""
|
||||||
Assert not empty
|
Assert not empty
|
||||||
|
@ -88,7 +88,6 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
|
|||||||
} as InputVar
|
} as InputVar
|
||||||
})()
|
})()
|
||||||
const updatePromptVariableItem = (payload: InputVar) => {
|
const updatePromptVariableItem = (payload: InputVar) => {
|
||||||
console.log(payload)
|
|
||||||
const newPromptVariables = produce(promptVariables, (draft) => {
|
const newPromptVariables = produce(promptVariables, (draft) => {
|
||||||
const { variable, label, type, ...rest } = payload
|
const { variable, label, type, ...rest } = payload
|
||||||
draft[currIndex] = {
|
draft[currIndex] = {
|
||||||
|
@ -28,6 +28,7 @@ export enum ComparisonOperator {
|
|||||||
lessThanOrEqual = '≤',
|
lessThanOrEqual = '≤',
|
||||||
isNull = 'is null',
|
isNull = 'is null',
|
||||||
isNotNull = 'is not null',
|
isNotNull = 'is not null',
|
||||||
|
regexMatch = 'regex match',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Condition = {
|
export type Condition = {
|
||||||
|
@ -30,6 +30,7 @@ export const getOperators = (type?: VarType) => {
|
|||||||
ComparisonOperator.isNot,
|
ComparisonOperator.isNot,
|
||||||
ComparisonOperator.empty,
|
ComparisonOperator.empty,
|
||||||
ComparisonOperator.notEmpty,
|
ComparisonOperator.notEmpty,
|
||||||
|
ComparisonOperator.regexMatch,
|
||||||
]
|
]
|
||||||
case VarType.number:
|
case VarType.number:
|
||||||
return [
|
return [
|
||||||
|
@ -412,6 +412,7 @@ const translation = {
|
|||||||
'not empty': 'is not empty',
|
'not empty': 'is not empty',
|
||||||
'null': 'is null',
|
'null': 'is null',
|
||||||
'not null': 'is not null',
|
'not null': 'is not null',
|
||||||
|
'regex match': 'regex match',
|
||||||
},
|
},
|
||||||
enterValue: 'Enter value',
|
enterValue: 'Enter value',
|
||||||
addCondition: 'Add Condition',
|
addCondition: 'Add Condition',
|
||||||
|
@ -412,6 +412,7 @@ const translation = {
|
|||||||
'not empty': '不为空',
|
'not empty': '不为空',
|
||||||
'null': '空',
|
'null': '空',
|
||||||
'not null': '不为空',
|
'not null': '不为空',
|
||||||
|
'regex match': '正则匹配',
|
||||||
},
|
},
|
||||||
enterValue: '输入值',
|
enterValue: '输入值',
|
||||||
addCondition: '添加条件',
|
addCondition: '添加条件',
|
||||||
|
Loading…
Reference in New Issue
Block a user