chore(api/core): apply ruff reformatting (#7624)
This commit is contained in:
@@ -7,11 +7,26 @@ class Condition(BaseModel):
|
||||
"""
|
||||
Condition entity
|
||||
"""
|
||||
|
||||
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",
|
||||
# for number
|
||||
"=", "≠", ">", "<", "≥", "≤", "null", "not null"
|
||||
"=",
|
||||
"≠",
|
||||
">",
|
||||
"<",
|
||||
"≥",
|
||||
"≤",
|
||||
"null",
|
||||
"not null",
|
||||
]
|
||||
value: Optional[str] = None
|
||||
|
@@ -15,9 +15,7 @@ class ConditionProcessor:
|
||||
index = 0
|
||||
for condition in conditions:
|
||||
index += 1
|
||||
actual_value = variable_pool.get_any(
|
||||
condition.variable_selector
|
||||
)
|
||||
actual_value = variable_pool.get_any(condition.variable_selector)
|
||||
|
||||
expected_value = None
|
||||
if condition.value is not None:
|
||||
@@ -25,9 +23,7 @@ class ConditionProcessor:
|
||||
variable_selectors = variable_template_parser.extract_variable_selectors()
|
||||
if variable_selectors:
|
||||
for variable_selector in variable_selectors:
|
||||
value = variable_pool.get_any(
|
||||
variable_selector.value_selector
|
||||
)
|
||||
value = variable_pool.get_any(variable_selector.value_selector)
|
||||
expected_value = variable_template_parser.format({variable_selector.variable: value})
|
||||
|
||||
if expected_value is None:
|
||||
@@ -40,7 +36,7 @@ class ConditionProcessor:
|
||||
{
|
||||
"actual_value": actual_value,
|
||||
"expected_value": expected_value,
|
||||
"comparison_operator": comparison_operator
|
||||
"comparison_operator": comparison_operator,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -50,10 +46,10 @@ class ConditionProcessor:
|
||||
return input_conditions, group_result
|
||||
|
||||
def evaluate_condition(
|
||||
self,
|
||||
actual_value: Optional[str | int | float | dict[Any, Any] | list[Any] | FileVar | None],
|
||||
comparison_operator: str,
|
||||
expected_value: Optional[str] = None
|
||||
self,
|
||||
actual_value: Optional[str | int | float | dict[Any, Any] | list[Any] | FileVar | None],
|
||||
comparison_operator: str,
|
||||
expected_value: Optional[str] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
Evaluate condition
|
||||
@@ -109,7 +105,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, str | list):
|
||||
raise ValueError('Invalid actual value type: string or array')
|
||||
raise ValueError("Invalid actual value type: string or array")
|
||||
|
||||
if expected_value not in actual_value:
|
||||
return False
|
||||
@@ -126,7 +122,7 @@ class ConditionProcessor:
|
||||
return True
|
||||
|
||||
if not isinstance(actual_value, str | list):
|
||||
raise ValueError('Invalid actual value type: string or array')
|
||||
raise ValueError("Invalid actual value type: string or array")
|
||||
|
||||
if expected_value in actual_value:
|
||||
return False
|
||||
@@ -143,7 +139,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, str):
|
||||
raise ValueError('Invalid actual value type: string')
|
||||
raise ValueError("Invalid actual value type: string")
|
||||
|
||||
if not actual_value.startswith(expected_value):
|
||||
return False
|
||||
@@ -160,7 +156,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, str):
|
||||
raise ValueError('Invalid actual value type: string')
|
||||
raise ValueError("Invalid actual value type: string")
|
||||
|
||||
if not actual_value.endswith(expected_value):
|
||||
return False
|
||||
@@ -177,7 +173,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, str):
|
||||
raise ValueError('Invalid actual value type: string')
|
||||
raise ValueError("Invalid actual value type: string")
|
||||
|
||||
if actual_value != expected_value:
|
||||
return False
|
||||
@@ -194,7 +190,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, str):
|
||||
raise ValueError('Invalid actual value type: string')
|
||||
raise ValueError("Invalid actual value type: string")
|
||||
|
||||
if actual_value == expected_value:
|
||||
return False
|
||||
@@ -231,7 +227,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, int | float):
|
||||
raise ValueError('Invalid actual value type: number')
|
||||
raise ValueError("Invalid actual value type: number")
|
||||
|
||||
if isinstance(actual_value, int):
|
||||
expected_value = int(expected_value)
|
||||
@@ -253,7 +249,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, int | float):
|
||||
raise ValueError('Invalid actual value type: number')
|
||||
raise ValueError("Invalid actual value type: number")
|
||||
|
||||
if isinstance(actual_value, int):
|
||||
expected_value = int(expected_value)
|
||||
@@ -275,7 +271,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, int | float):
|
||||
raise ValueError('Invalid actual value type: number')
|
||||
raise ValueError("Invalid actual value type: number")
|
||||
|
||||
if isinstance(actual_value, int):
|
||||
expected_value = int(expected_value)
|
||||
@@ -297,7 +293,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, int | float):
|
||||
raise ValueError('Invalid actual value type: number')
|
||||
raise ValueError("Invalid actual value type: number")
|
||||
|
||||
if isinstance(actual_value, int):
|
||||
expected_value = int(expected_value)
|
||||
@@ -308,8 +304,9 @@ class ConditionProcessor:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _assert_greater_than_or_equal(self, actual_value: Optional[int | float],
|
||||
expected_value: str | int | float) -> bool:
|
||||
def _assert_greater_than_or_equal(
|
||||
self, actual_value: Optional[int | float], expected_value: str | int | float
|
||||
) -> bool:
|
||||
"""
|
||||
Assert greater than or equal
|
||||
:param actual_value: actual value
|
||||
@@ -320,7 +317,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, int | float):
|
||||
raise ValueError('Invalid actual value type: number')
|
||||
raise ValueError("Invalid actual value type: number")
|
||||
|
||||
if isinstance(actual_value, int):
|
||||
expected_value = int(expected_value)
|
||||
@@ -331,8 +328,9 @@ class ConditionProcessor:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _assert_less_than_or_equal(self, actual_value: Optional[int | float],
|
||||
expected_value: str | int | float) -> bool:
|
||||
def _assert_less_than_or_equal(
|
||||
self, actual_value: Optional[int | float], expected_value: str | int | float
|
||||
) -> bool:
|
||||
"""
|
||||
Assert less than or equal
|
||||
:param actual_value: actual value
|
||||
@@ -343,7 +341,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
|
||||
if not isinstance(actual_value, int | float):
|
||||
raise ValueError('Invalid actual value type: number')
|
||||
raise ValueError("Invalid actual value type: number")
|
||||
|
||||
if isinstance(actual_value, int):
|
||||
expected_value = int(expected_value)
|
||||
|
@@ -5,7 +5,7 @@ from typing import Any
|
||||
from core.workflow.entities.variable_entities import VariableSelector
|
||||
from core.workflow.entities.variable_pool import VariablePool
|
||||
|
||||
REGEX = re.compile(r'\{\{(#[a-zA-Z0-9_]{1,50}(\.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10}#)\}\}')
|
||||
REGEX = re.compile(r"\{\{(#[a-zA-Z0-9_]{1,50}(\.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10}#)\}\}")
|
||||
|
||||
|
||||
def parse_mixed_template(*, template: str, variable_pool: VariablePool) -> str:
|
||||
@@ -20,7 +20,7 @@ def parse_mixed_template(*, template: str, variable_pool: VariablePool) -> str:
|
||||
# e.g. ('#node_id.query.name#', ['node_id', 'query', 'name'])
|
||||
key_selectors = filter(
|
||||
lambda t: len(t[1]) >= 2,
|
||||
((key, selector.replace('#', '').split('.')) for key, selector in zip(variable_keys, variable_keys)),
|
||||
((key, selector.replace("#", "").split(".")) for key, selector in zip(variable_keys, variable_keys)),
|
||||
)
|
||||
inputs = {key: variable_pool.get_any(selector) for key, selector in key_selectors}
|
||||
|
||||
@@ -29,13 +29,13 @@ def parse_mixed_template(*, template: str, variable_pool: VariablePool) -> str:
|
||||
# return original matched string if key not found
|
||||
value = inputs.get(key, match.group(0))
|
||||
if value is None:
|
||||
value = ''
|
||||
value = ""
|
||||
value = str(value)
|
||||
# remove template variables if required
|
||||
return re.sub(REGEX, r'{\1}', value)
|
||||
return re.sub(REGEX, r"{\1}", value)
|
||||
|
||||
result = re.sub(REGEX, replacer, template)
|
||||
result = re.sub(r'<\|.*?\|>', '', result)
|
||||
result = re.sub(r"<\|.*?\|>", "", result)
|
||||
return result
|
||||
|
||||
|
||||
@@ -101,8 +101,8 @@ class VariableTemplateParser:
|
||||
"""
|
||||
variable_selectors = []
|
||||
for variable_key in self.variable_keys:
|
||||
remove_hash = variable_key.replace('#', '')
|
||||
split_result = remove_hash.split('.')
|
||||
remove_hash = variable_key.replace("#", "")
|
||||
split_result = remove_hash.split(".")
|
||||
if len(split_result) < 2:
|
||||
continue
|
||||
|
||||
@@ -127,7 +127,7 @@ class VariableTemplateParser:
|
||||
value = inputs.get(key, match.group(0)) # return original matched string if key not found
|
||||
|
||||
if value is None:
|
||||
value = ''
|
||||
value = ""
|
||||
# convert the value to string
|
||||
if isinstance(value, list | dict | bool | int | float):
|
||||
value = str(value)
|
||||
@@ -136,7 +136,7 @@ class VariableTemplateParser:
|
||||
return VariableTemplateParser.remove_template_variables(value)
|
||||
|
||||
prompt = re.sub(REGEX, replacer, self.template)
|
||||
return re.sub(r'<\|.*?\|>', '', prompt)
|
||||
return re.sub(r"<\|.*?\|>", "", prompt)
|
||||
|
||||
@classmethod
|
||||
def remove_template_variables(cls, text: str):
|
||||
@@ -149,4 +149,4 @@ class VariableTemplateParser:
|
||||
Returns:
|
||||
The text with template variables removed.
|
||||
"""
|
||||
return re.sub(REGEX, r'{\1}', text)
|
||||
return re.sub(REGEX, r"{\1}", text)
|
||||
|
Reference in New Issue
Block a user