From a963ea2773c85d2cbbe05245b016d7a5d5df2f04 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 25 Jul 2024 10:46:46 -0300 Subject: [PATCH 1/8] refactor: update StateVertex class to inherit from ComponentVertex The StateVertex class in types.py has been updated to inherit from the ComponentVertex class instead of the Vertex class. This change ensures that the StateVertex class has access to the methods and attributes of the ComponentVertex class, improving code organization and maintainability. --- src/backend/base/langflow/graph/vertex/types.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/graph/vertex/types.py b/src/backend/base/langflow/graph/vertex/types.py index cd330aa0aa2..3db16a17c98 100644 --- a/src/backend/base/langflow/graph/vertex/types.py +++ b/src/backend/base/langflow/graph/vertex/types.py @@ -404,7 +404,7 @@ def _is_chat_input(self): return self.vertex_type == InterfaceComponentTypes.ChatInput and self.is_input -class StateVertex(Vertex): +class StateVertex(ComponentVertex): def __init__(self, data: Dict, graph): super().__init__(data, graph=graph, base_type="custom_components") self.steps = [self._build] @@ -412,8 +412,9 @@ def __init__(self, data: Dict, graph): @property def successors_ids(self) -> List[str]: - successors = self.graph.successor_map.get(self.id, []) - return successors + self.graph.activated_vertices + if self._successors_ids is None: + return super().successors_ids + return self._successors_ids def _built_object_repr(self): if self.artifacts and "repr" in self.artifacts: From 0cb272f2e1ac444670dc8a01ddc9801dc87241d6 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 25 Jul 2024 10:46:53 -0300 Subject: [PATCH 2/8] feat: add _successors_ids attribute to Vertex class The Vertex class in base.py has been updated to include a new attribute `_successors_ids`. This attribute will store the IDs of the successors of the vertex. This change improves the functionality and flexibility of the Vertex class. --- src/backend/base/langflow/graph/vertex/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/base/langflow/graph/vertex/base.py b/src/backend/base/langflow/graph/vertex/base.py index 6d1d27f4eec..1fc6a08cc6a 100644 --- a/src/backend/base/langflow/graph/vertex/base.py +++ b/src/backend/base/langflow/graph/vertex/base.py @@ -71,6 +71,7 @@ def __init__( self._built_object = UnbuiltObject() self._built_result = None self._built = False + self._successors_ids: Optional[List[str]] = None self.artifacts: Dict[str, Any] = {} self.artifacts_raw: Dict[str, Any] = {} self.artifacts_type: Dict[str, str] = {} From 2fdbaf9f92b5ed5924ed131d5d865ab6eb3386db Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 25 Jul 2024 10:47:00 -0300 Subject: [PATCH 3/8] feat: add _set_successors_ids method to NotifyComponent This commit adds a new method `_set_successors_ids` to the `NotifyComponent` class in `Notify.py`. This method retrieves the successors of the vertex and sets the `successors_ids` attribute accordingly. This change improves the functionality and flexibility of the `NotifyComponent` class. --- src/backend/base/langflow/components/prototypes/Notify.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/backend/base/langflow/components/prototypes/Notify.py b/src/backend/base/langflow/components/prototypes/Notify.py index c07baae34eb..30528537f8f 100644 --- a/src/backend/base/langflow/components/prototypes/Notify.py +++ b/src/backend/base/langflow/components/prototypes/Notify.py @@ -39,4 +39,9 @@ def build(self, name: str, data: Optional[Data] = None, append: bool = False) -> else: self.status = "No record provided." self.status = data + self._set_successors_ids() return data + + def _set_successors_ids(self): + successors = self.vertex.graph.successor_map.get(self.vertex.id, []) + return successors + self.vertex.graph.activated_vertices From 76ec3b99ecbe7d5f8f953af34826ffdab3f500a7 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 25 Jul 2024 10:47:05 -0300 Subject: [PATCH 4/8] refactor: add _set_successors_ids method to ListenComponent This commit adds a new method `_set_successors_ids` to the `ListenComponent` class in `Listen.py`. This method retrieves the successors of the vertex and sets the `successors_ids` attribute accordingly. This change improves the functionality and flexibility of the `ListenComponent` class. --- src/backend/base/langflow/components/prototypes/Listen.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/backend/base/langflow/components/prototypes/Listen.py b/src/backend/base/langflow/components/prototypes/Listen.py index 23b9c3ee13d..146df3bfdc4 100644 --- a/src/backend/base/langflow/components/prototypes/Listen.py +++ b/src/backend/base/langflow/components/prototypes/Listen.py @@ -18,5 +18,10 @@ def build_config(self): def build(self, name: str) -> Data: state = self.get_state(name) + self._set_successors_ids() self.status = state return state + + def _set_successors_ids(self): + successors = self.vertex.graph.successor_map.get(self.vertex.id, []) + return successors + self.vertex.graph.activated_vertices From 9ae23235d8798341b3da5cb67cd229e187f5769d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 25 Jul 2024 10:49:42 -0300 Subject: [PATCH 5/8] refactor: update StateVertex class to not be a state This commit updates the StateVertex class in types.py to no longer be considered a state. The `is_state` attribute is set to False, ensuring that the vertex is not treated as a state. This change improves code clarity and aligns with the intended functionality of the class. --- src/backend/base/langflow/graph/vertex/types.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/graph/vertex/types.py b/src/backend/base/langflow/graph/vertex/types.py index 3db16a17c98..7408c98a3b2 100644 --- a/src/backend/base/langflow/graph/vertex/types.py +++ b/src/backend/base/langflow/graph/vertex/types.py @@ -408,11 +408,12 @@ class StateVertex(ComponentVertex): def __init__(self, data: Dict, graph): super().__init__(data, graph=graph, base_type="custom_components") self.steps = [self._build] - self.is_state = True + self.is_state = False @property def successors_ids(self) -> List[str]: if self._successors_ids is None: + self.is_state = False return super().successors_ids return self._successors_ids From 5b4440f2c0c73f7f05952480e31bf9b7463adae5 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 25 Jul 2024 10:49:54 -0300 Subject: [PATCH 6/8] refactor: set is_state attribute to True in ListenComponent This commit sets the `is_state` attribute to True in the `ListenComponent` class in `Listen.py`. This change ensures that the `ListenComponent` is treated as a state and improves the functionality of the component. --- src/backend/base/langflow/components/prototypes/Listen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/base/langflow/components/prototypes/Listen.py b/src/backend/base/langflow/components/prototypes/Listen.py index 146df3bfdc4..6e5de723a87 100644 --- a/src/backend/base/langflow/components/prototypes/Listen.py +++ b/src/backend/base/langflow/components/prototypes/Listen.py @@ -23,5 +23,6 @@ def build(self, name: str) -> Data: return state def _set_successors_ids(self): + self.vertex.is_state = True successors = self.vertex.graph.successor_map.get(self.vertex.id, []) return successors + self.vertex.graph.activated_vertices From aad82f664cccde8e181fe709d85e8daa16a450f3 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 25 Jul 2024 10:49:59 -0300 Subject: [PATCH 7/8] refactor: set is_state attribute to True in NotifyComponent --- src/backend/base/langflow/components/prototypes/Notify.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/base/langflow/components/prototypes/Notify.py b/src/backend/base/langflow/components/prototypes/Notify.py index 30528537f8f..b83331e3a91 100644 --- a/src/backend/base/langflow/components/prototypes/Notify.py +++ b/src/backend/base/langflow/components/prototypes/Notify.py @@ -43,5 +43,6 @@ def build(self, name: str, data: Optional[Data] = None, append: bool = False) -> return data def _set_successors_ids(self): + self.vertex.is_state = True successors = self.vertex.graph.successor_map.get(self.vertex.id, []) return successors + self.vertex.graph.activated_vertices From 7550f5e49f36e3e3ef4953d16631d6977b1568e9 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 25 Jul 2024 11:49:53 -0300 Subject: [PATCH 8/8] refactor: remove base_type argument from StateVertex constructor This commit removes the `base_type` argument from the constructor of the `StateVertex` class in `types.py`. The `base_type` argument was not being used and was unnecessary for the functionality of the class. This change improves code clarity and removes unnecessary code. --- src/backend/base/langflow/graph/vertex/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/base/langflow/graph/vertex/types.py b/src/backend/base/langflow/graph/vertex/types.py index 7408c98a3b2..78c541f651e 100644 --- a/src/backend/base/langflow/graph/vertex/types.py +++ b/src/backend/base/langflow/graph/vertex/types.py @@ -406,7 +406,7 @@ def _is_chat_input(self): class StateVertex(ComponentVertex): def __init__(self, data: Dict, graph): - super().__init__(data, graph=graph, base_type="custom_components") + super().__init__(data, graph=graph) self.steps = [self._build] self.is_state = False