From eca66c518d6679bb3410ac62ad284cd6673ea5a2 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 24 Mar 2024 17:35:50 -0300 Subject: [PATCH] Fix duplicated first layer results --- src/backend/langflow/api/v1/chat.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 8cdeb6f05..08864e7e4 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -65,19 +65,25 @@ async def get_vertices( graph = await build_and_cache_graph(flow_id, session, chat_service, graph) if stop_component_id or start_component_id: try: - vertices = graph.sort_vertices(stop_component_id, start_component_id) + first_layer = graph.sort_vertices(stop_component_id, start_component_id) except Exception as exc: logger.error(exc) - vertices = graph.sort_vertices() + first_layer = graph.sort_vertices() else: - vertices = graph.sort_vertices() + first_layer = graph.sort_vertices() + # When we send vertices to the frontend + # we need to remove them from the predecessors + # so they are not considered for building again + # which duplicates the results + for vertex_id in first_layer: + graph.remove_from_predecessors(vertex_id) # Now vertices is a list of lists # We need to get the id of each vertex # and return the same structure but only with the ids run_id = uuid.uuid4() graph.set_run_id(run_id) - return VerticesOrderResponse(ids=vertices, run_id=run_id) + return VerticesOrderResponse(ids=first_layer, run_id=run_id) except Exception as exc: logger.error(f"Error checking build status: {exc}")