fix: Ensure chat inputs with dependencies are not prioritized in graph sorting (#4666)
Ensure chat inputs with dependencies are not sorted to the first layer in graph.
This commit is contained in:
parent
a86a7a2df6
commit
13620629d1
1 changed files with 8 additions and 0 deletions
|
|
@ -1928,6 +1928,13 @@ class Graph:
|
||||||
return [layer for layer in refined_layers if layer]
|
return [layer for layer in refined_layers if layer]
|
||||||
|
|
||||||
def sort_chat_inputs_first(self, vertices_layers: list[list[str]]) -> list[list[str]]:
|
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 = []
|
chat_inputs_first = []
|
||||||
for layer in vertices_layers:
|
for layer in vertices_layers:
|
||||||
layer_chat_inputs_first = [vertex_id for vertex_id in layer if "ChatInput" in vertex_id]
|
layer_chat_inputs_first = [vertex_id for vertex_id in layer if "ChatInput" in vertex_id]
|
||||||
|
|
@ -1935,6 +1942,7 @@ class Graph:
|
||||||
for vertex_id in layer_chat_inputs_first:
|
for vertex_id in layer_chat_inputs_first:
|
||||||
# Remove the ChatInput from the layer
|
# Remove the ChatInput from the layer
|
||||||
layer.remove(vertex_id)
|
layer.remove(vertex_id)
|
||||||
|
|
||||||
if not chat_inputs_first:
|
if not chat_inputs_first:
|
||||||
return vertices_layers
|
return vertices_layers
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue