mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 09:28:04 +08:00
optimize graph
This commit is contained in:
@ -14,4 +14,6 @@ class Condition(BaseModel):
|
||||
# for number
|
||||
"=", "≠", ">", "<", "≥", "≤", "null", "not null"
|
||||
]
|
||||
value_type: Literal["string", "value_selector"] = "string"
|
||||
value: Optional[str] = None
|
||||
value_selector: Optional[list[str]] = None
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from core.workflow.entities.node_entities import NodeRunResult
|
||||
from core.workflow.entities.workflow_runtime_state_entities import WorkflowRuntimeState
|
||||
from core.workflow.graph import GraphNode
|
||||
|
||||
|
||||
def source_handle_condition_func(workflow_runtime_state: WorkflowRuntimeState,
|
||||
graph_node: GraphNode,
|
||||
# TODO cycle_state optional
|
||||
predecessor_node_run_result: Optional[NodeRunResult] = None) -> bool:
|
||||
if not graph_node.source_edge_config:
|
||||
return False
|
||||
|
||||
if not graph_node.source_edge_config.get('sourceHandle'):
|
||||
return True
|
||||
|
||||
source_handle = predecessor_node_run_result.edge_source_handle \
|
||||
if predecessor_node_run_result else None
|
||||
|
||||
return (source_handle is not None
|
||||
and graph_node.source_edge_config.get('sourceHandle') == source_handle)
|
||||
@ -24,7 +24,12 @@ class ConditionProcessor:
|
||||
variable_selector=condition.variable_selector
|
||||
)
|
||||
|
||||
expected_value = condition.value
|
||||
if condition.value_type == "value_selector":
|
||||
expected_value = variable_pool.get_variable_value(
|
||||
variable_selector=condition.value_selector
|
||||
)
|
||||
else:
|
||||
expected_value = condition.value
|
||||
|
||||
input_conditions.append({
|
||||
"actual_value": actual_value,
|
||||
@ -208,7 +213,7 @@ class ConditionProcessor:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _assert_equal(self, actual_value: Optional[int | float], expected_value: str) -> bool:
|
||||
def _assert_equal(self, actual_value: Optional[int | float], expected_value: str | int | float) -> bool:
|
||||
"""
|
||||
Assert equal
|
||||
:param actual_value: actual value
|
||||
@ -230,7 +235,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _assert_not_equal(self, actual_value: Optional[int | float], expected_value: str) -> bool:
|
||||
def _assert_not_equal(self, actual_value: Optional[int | float], expected_value: str | int | float) -> bool:
|
||||
"""
|
||||
Assert not equal
|
||||
:param actual_value: actual value
|
||||
@ -252,7 +257,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _assert_greater_than(self, actual_value: Optional[int | float], expected_value: str) -> bool:
|
||||
def _assert_greater_than(self, actual_value: Optional[int | float], expected_value: str | int | float) -> bool:
|
||||
"""
|
||||
Assert greater than
|
||||
:param actual_value: actual value
|
||||
@ -274,7 +279,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _assert_less_than(self, actual_value: Optional[int | float], expected_value: str) -> bool:
|
||||
def _assert_less_than(self, actual_value: Optional[int | float], expected_value: str | int | float) -> bool:
|
||||
"""
|
||||
Assert less than
|
||||
:param actual_value: actual value
|
||||
@ -296,7 +301,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _assert_greater_than_or_equal(self, actual_value: Optional[int | float], expected_value: str) -> 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
|
||||
@ -318,7 +323,7 @@ class ConditionProcessor:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _assert_less_than_or_equal(self, actual_value: Optional[int | float], expected_value: str) -> 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
|
||||
|
||||
Reference in New Issue
Block a user