Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update StateVertex to function like a normal component unless specified not to #2950

Merged
merged 9 commits into from
Jul 25, 2024
6 changes: 6 additions & 0 deletions src/backend/base/langflow/components/prototypes/Listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ 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):
self.vertex.is_state = True
successors = self.vertex.graph.successor_map.get(self.vertex.id, [])
return successors + self.vertex.graph.activated_vertices
6 changes: 6 additions & 0 deletions src/backend/base/langflow/components/prototypes/Notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ 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):
self.vertex.is_state = True
successors = self.vertex.graph.successor_map.get(self.vertex.id, [])
return successors + self.vertex.graph.activated_vertices
1 change: 1 addition & 0 deletions src/backend/base/langflow/graph/vertex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
12 changes: 7 additions & 5 deletions src/backend/base/langflow/graph/vertex/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,18 @@ 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")
super().__init__(data, graph=graph)
self.steps = [self._build]
self.is_state = True
self.is_state = False

@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:
self.is_state = False
return super().successors_ids
return self._successors_ids

def _built_object_repr(self):
if self.artifacts and "repr" in self.artifacts:
Expand Down