From 38da096245d97053c51ea7efc22ad0505d3798de Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 13 Jul 2023 15:01:08 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20rename=20=5Fremo?= =?UTF-8?q?ve=5Finvalid=5Fnodes()=20to=20=5Fvalidate=5Fnodes()=20for=20cla?= =?UTF-8?q?rity=20and=20accuracy=20=F0=9F=94=A5=20chore(base.py):=20remove?= =?UTF-8?q?=20unnecessary=20check=20for=20single=20node=20and=20no=20edges?= =?UTF-8?q?=20in=20=5Fvalidate=5Fnodes()=20=F0=9F=94=A5=20chore(base.py):?= =?UTF-8?q?=20remove=20unused=20import=20statement=20=F0=9F=94=A5=20chore(?= =?UTF-8?q?base.py):=20remove=20unused=20=5Fvalidate=5Fnode()=20method=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(base.py):=20remove=20unused=20import=20sta?= =?UTF-8?q?tement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/graph/base.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/backend/langflow/graph/graph/base.py b/src/backend/langflow/graph/graph/base.py index 86a2f98a9..0d93dd0db 100644 --- a/src/backend/langflow/graph/graph/base.py +++ b/src/backend/langflow/graph/graph/base.py @@ -60,7 +60,7 @@ class Graph: # the toolkit node self._build_node_params() # remove invalid nodes - self._remove_invalid_nodes() + self._validate_nodes() def _build_node_params(self) -> None: """Identifies and handles the LLM node within the graph.""" @@ -75,14 +75,13 @@ class Graph: if isinstance(node, ToolkitVertex): node.params["llm"] = llm_node - def _remove_invalid_nodes(self) -> None: - """Removes invalid nodes from the graph.""" - self.nodes = [ - node - for node in self.nodes - if self._validate_node(node) - or (len(self.nodes) == 1 and len(self.edges) == 0) - ] + def _validate_nodes(self) -> None: + """Check that all nodes have edges""" + for node in self.nodes: + if not self._validate_node(node): + raise ValueError( + f"{node.vertex_type} is not connected to any other components" + ) def _validate_node(self, node: Vertex) -> bool: """Validates a node."""