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

fix: Ensure chat inputs with dependencies are not prioritized in graph sorting #4666

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/backend/base/langflow/graph/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,13 +1928,21 @@ def refine_layers(self, initial_layers):
return [layer for layer in refined_layers if layer]

def sort_chat_inputs_first(self, vertices_layers: list[list[str]]) -> list[list[str]]:
# First check if any chat inputs have dependencies
for layer in vertices_layers:
for vertex_id in layer:
if "ChatInput" in vertex_id and self.get_predecessors(self.get_vertex(vertex_id)):
return vertices_layers

# If no chat inputs have dependencies, move them to first layer
chat_inputs_first = []
for layer in vertices_layers:
layer_chat_inputs_first = [vertex_id for vertex_id in layer if "ChatInput" in vertex_id]
chat_inputs_first.extend(layer_chat_inputs_first)
for vertex_id in layer_chat_inputs_first:
# Remove the ChatInput from the layer
layer.remove(vertex_id)

if not chat_inputs_first:
return vertices_layers

Expand Down