Refactor vertex running logic in Graph class

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-03 18:46:31 -03:00
commit c87c213feb
2 changed files with 11 additions and 1 deletions

View file

@ -125,6 +125,9 @@ async def build_vertex(
else:
raise ValueError(f"No result found for vertex {vertex_id}")
next_vertices_ids = vertex.successors_ids
next_vertices_ids = [
v for v in next_vertices_ids if graph.should_run_vertex(v)
]
result_data_response = ResultDataResponse(**result_dict.model_dump())
except Exception as exc:

View file

@ -773,14 +773,21 @@ class Graph:
vertices = self.vertices
vertices_layers = self.layered_topological_sort(vertices)
vertices_layers = self.sort_by_avg_build_time(vertices_layers)
vertices_layers = self.sort_chat_inputs_first(vertices_layers)
# vertices_layers = self.sort_chat_inputs_first(vertices_layers)
self.increment_run_count()
first_layer = vertices_layers[0]
# save the only the rest
self.vertices_layers = vertices_layers[1:]
self.vertices_to_run = {
vertex for vertex in chain.from_iterable(vertices_layers)
}
# Return just the first layer
return first_layer
def should_run_vertex(self, vertex_id: str) -> bool:
"""Returns whether a component should be run."""
return vertex_id in self.vertices_to_run
def sort_interface_components_first(
self, vertices_layers: List[List[str]]
) -> List[List[str]]: