Add sorting of vertices based on InterfaceComponentTypes
This commit is contained in:
parent
d0880c6c62
commit
51f39223d4
3 changed files with 24 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ from langchain.chains.base import Chain
|
|||
from langflow.graph.edge.base import ContractEdge
|
||||
from langflow.graph.graph.constants import lazy_load_vertex_dict
|
||||
from langflow.graph.graph.utils import process_flow
|
||||
from langflow.graph.schema import InterfaceComponentTypes
|
||||
from langflow.graph.vertex.base import Vertex
|
||||
from langflow.graph.vertex.types import (
|
||||
ChatVertex,
|
||||
|
|
@ -453,4 +454,18 @@ class Graph:
|
|||
def sort_vertices(self) -> List[List[str]]:
|
||||
"""Sorts the vertices in the graph."""
|
||||
vertices = self.layered_topological_sort()
|
||||
# Sort each layer to have ChatInput or ChatOutput first
|
||||
# each layer consists of a list of vertex ids
|
||||
# formatted as ComponentName-5letters
|
||||
# e.g. ChatInput-abcde
|
||||
# we just need to check if the vertex id contains ChatInput or ChatOutput
|
||||
# and sort the layers accordingly
|
||||
# InterfaceComponentTypes is an enum
|
||||
for layer in vertices:
|
||||
layer.sort(
|
||||
key=lambda x: any(
|
||||
InterfaceComponentTypes.CHAT_INPUT.value in x,
|
||||
InterfaceComponentTypes.CHAT_OUTPUT.value in x,
|
||||
)
|
||||
)
|
||||
return self.sort_chat_inputs_first(vertices)
|
||||
|
|
|
|||
8
src/backend/langflow/graph/schema.py
Normal file
8
src/backend/langflow/graph/schema.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class InterfaceComponentTypes(Enum):
|
||||
# ChatInput and ChatOutput are the only ones that are
|
||||
# power components
|
||||
ChatInput = "ChatInput"
|
||||
ChatOutput = "ChatOutput"
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import ast
|
||||
import inspect
|
||||
import types
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Dict, List, Optional
|
||||
from langflow.graph.schema import InterfaceComponentTypes
|
||||
|
||||
from langflow.graph.utils import UnbuiltObject, UnbuiltResult
|
||||
from langflow.graph.vertex.utils import generate_result
|
||||
|
|
@ -18,13 +18,6 @@ if TYPE_CHECKING:
|
|||
from langflow.graph.graph.base import Graph
|
||||
|
||||
|
||||
class InterfaceComponentTypes(Enum):
|
||||
# ChatInput and ChatOutput are the only ones that are
|
||||
# power components
|
||||
ChatInput = "ChatInput"
|
||||
ChatOutput = "ChatOutput"
|
||||
|
||||
|
||||
class Vertex:
|
||||
def __init__(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue