diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 258277bca..0c8719527 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -18,6 +18,7 @@ from langflow.api.v1.schemas import ( VertexBuildResponse, VerticesOrderResponse, ) +from langflow.graph.utils import UnbuiltResult from langflow.services.auth.utils import get_current_active_user from langflow.services.chat.service import ChatService from langflow.services.deps import get_chat_service, get_session, get_session_service @@ -116,7 +117,7 @@ async def build_vertex( inputs_dict = inputs.model_dump() if inputs else {} await vertex.build(user_id=current_user.id, inputs=inputs_dict) - if vertex.result is not None: + if not isinstance(vertex.result, UnbuiltResult): params = vertex._built_object_repr() valid = True result_dict = vertex.result diff --git a/src/backend/langflow/graph/graph/base.py b/src/backend/langflow/graph/graph/base.py index 453076e1b..51dd53775 100644 --- a/src/backend/langflow/graph/graph/base.py +++ b/src/backend/langflow/graph/graph/base.py @@ -10,7 +10,7 @@ from langflow.graph.graph.constants import lazy_load_vertex_dict from langflow.graph.graph.state_manager import GraphStateManager from langflow.graph.graph.utils import process_flow from langflow.graph.schema import INPUT_FIELD_NAME, InterfaceComponentTypes -from langflow.graph.vertex.base import Vertex +from langflow.graph.vertex.base import Vertex, VertexStates from langflow.graph.vertex.types import ( ChatVertex, FileToolVertex, @@ -148,17 +148,17 @@ class Graph: def reset_inactive_vertices(self): self.inactive_vertices = set() - def mark_all_vertices(self, state: str): + def mark_all_vertices(self, state: "VertexStates"): """Marks all vertices in the graph.""" for vertex in self.vertices: vertex.set_state(state) - def mark_vertex(self, vertex_id: str, state: str): + def mark_vertex(self, vertex_id: str, state: "VertexStates"): """Marks a vertex in the graph.""" vertex = self.get_vertex(vertex_id) vertex.set_state(state) - def mark_branch(self, vertex_id: str, state: str): + def mark_branch(self, vertex_id: str, state: "VertexStates"): """Marks a branch of the graph.""" self.mark_vertex(vertex_id, state) for child_id in self.parent_child_map[vertex_id]: @@ -552,7 +552,7 @@ class Graph: node_name = node_id.split("-")[0] if node_name in ["ChatOutput", "ChatInput"]: return ChatVertex - elif node_name in ["ShouldRunNext"]: + elif node_name in ["ShouldRunNext", "Branch"]: return RoutingVertex elif node_base_type in lazy_load_vertex_dict.VERTEX_TYPE_MAP: return lazy_load_vertex_dict.VERTEX_TYPE_MAP[node_base_type] diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 6425f5e08..25e8188f3 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -2,7 +2,7 @@ import ast import inspect import types from enum import Enum -from typing import TYPE_CHECKING, Any, Callable, Coroutine, Dict, List, Optional +from typing import TYPE_CHECKING, Any, Callable, Coroutine, Dict, List, Optional, Union from loguru import logger @@ -75,7 +75,7 @@ class Vertex: self.parent_is_top_level = False self.layer = None self.should_run = True - self.result: Optional[ResultData] = None + self.result: Union[ResultData, UnbuiltResult] = UnbuiltResult() try: self.is_interface_component = self.vertex_type in InterfaceComponentTypes except ValueError: @@ -95,11 +95,12 @@ class Vertex: else: self.graph_state[key] = new_state - def set_state(self, state: str): - self.state = VertexStates[state] + def set_state(self, state: "VertexStates"): + self.state = state if ( - self.state == VertexStates.INACTIVE - and self.graph.in_degree_map[self.id] < 2 + self.state + == VertexStates.INACTIVE + # and self.graph.in_degree_map[self.id] < 2 ): # If the vertex is inactive and has only one in degree # it means that it is not a merge point in the graph