mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 02:25:52 +08:00
add runtime graph
This commit is contained in:
parent
8217c46116
commit
fe27c97fd9
@ -0,0 +1,66 @@
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from core.app.entities.app_invoke_entities import InvokeFrom
|
||||
from core.workflow.entities.node_entities import NodeRunResult
|
||||
from core.workflow.entities.variable_pool import VariablePool
|
||||
from core.workflow.graph import Graph, GraphNode
|
||||
from core.workflow.nodes.base_node import BaseNode, UserFrom
|
||||
from models.workflow import WorkflowType
|
||||
|
||||
|
||||
class RuntimeNode(BaseModel):
|
||||
class Status(Enum):
|
||||
RUNNING = "running"
|
||||
SUCCESS = "success"
|
||||
FAILED = "failed"
|
||||
PAUSED = "paused"
|
||||
|
||||
id: str
|
||||
"""random id for current runtime node"""
|
||||
|
||||
graph_node: GraphNode
|
||||
"""graph node"""
|
||||
|
||||
node_instance: BaseNode
|
||||
"""node instance"""
|
||||
|
||||
node_run_result: Optional[NodeRunResult] = None
|
||||
"""node run result"""
|
||||
|
||||
status: Status = Status.RUNNING
|
||||
"""node status"""
|
||||
|
||||
start_at: float
|
||||
"""start time"""
|
||||
|
||||
paused_at: Optional[float] = None
|
||||
"""paused time"""
|
||||
|
||||
finished_at: Optional[float] = None
|
||||
"""finished time"""
|
||||
|
||||
failed_reason: Optional[str] = None
|
||||
"""failed reason"""
|
||||
|
||||
paused_by: Optional[str] = None
|
||||
"""paused by"""
|
||||
|
||||
|
||||
class WorkflowRuntimeState(BaseModel):
|
||||
tenant_id: str
|
||||
app_id: str
|
||||
workflow_id: str
|
||||
workflow_type: WorkflowType
|
||||
user_id: str
|
||||
user_from: UserFrom
|
||||
variable_pool: VariablePool
|
||||
invoke_from: InvokeFrom
|
||||
graph: Graph
|
||||
call_depth: int
|
||||
start_at: float
|
||||
|
||||
total_tokens: int = 0
|
||||
node_run_steps: int = 0
|
@ -29,14 +29,14 @@ class GraphNode(BaseModel):
|
||||
target_edge_config: Optional[dict] = None
|
||||
"""original target edge config"""
|
||||
|
||||
sub_graph: Optional["Graph"] = None
|
||||
"""sub graph for iteration or loop node"""
|
||||
|
||||
def add_child(self, node_id: str) -> None:
|
||||
self.children_node_ids.append(node_id)
|
||||
|
||||
|
||||
class Graph(BaseModel):
|
||||
graph: dict
|
||||
"""graph from workflow"""
|
||||
|
||||
graph_nodes: dict[str, GraphNode] = {}
|
||||
"""graph nodes"""
|
||||
|
||||
@ -46,7 +46,6 @@ class Graph(BaseModel):
|
||||
def add_edge(self, edge_config: dict,
|
||||
source_node_config: dict,
|
||||
target_node_config: dict,
|
||||
source_node_sub_graph: Optional["Graph"] = None,
|
||||
is_continue_callback: Optional[Callable] = None) -> None:
|
||||
"""
|
||||
Add edge to the graph
|
||||
@ -54,7 +53,6 @@ class Graph(BaseModel):
|
||||
:param edge_config: edge config
|
||||
:param source_node_config: source node config
|
||||
:param target_node_config: target node config
|
||||
:param source_node_sub_graph: sub graph for iteration or loop node
|
||||
:param is_continue_callback: condition callback
|
||||
"""
|
||||
source_node_id = source_node_config.get('id')
|
||||
@ -71,7 +69,6 @@ class Graph(BaseModel):
|
||||
node_config=source_node_config,
|
||||
children_node_ids=[target_node_id],
|
||||
target_edge_config=edge_config,
|
||||
sub_graph=source_node_sub_graph
|
||||
)
|
||||
|
||||
self.add_graph_node(source_graph_node)
|
||||
@ -79,7 +76,6 @@ class Graph(BaseModel):
|
||||
source_node = self.graph_nodes[source_node_id]
|
||||
source_node.add_child(target_node_id)
|
||||
source_node.target_edge_config = edge_config
|
||||
source_node.sub_graph = source_node_sub_graph
|
||||
|
||||
source_handle = None
|
||||
if edge_config.get('sourceHandle'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user