Giter Club home page Giter Club logo

Comments (1)

dosubot avatar dosubot commented on July 1, 2024 2

To avoid confusion caused by the term vertex, you can replace it with a more descriptive term such as node. Here is the corrected version of the error message and related code:

from langflow.graph.node import types
from langflow.interface.agents.base import agent_creator
from langflow.interface.chains.base import chain_creator
from langflow.interface.custom.base import custom_component_creator
from langflow.interface.document_loaders.base import documentloader_creator
from langflow.interface.embeddings.base import embedding_creator
from langflow.interface.llms.base import llm_creator
from langflow.interface.memories.base import memory_creator
from langflow.interface.output_parsers.base import output_parser_creator
from langflow.interface.prompts.base import prompt_creator
from langflow.interface.retrievers.base import retriever_creator
from langflow.interface.text_splitters.base import textsplitter_creator
from langflow.interface.toolkits.base import toolkits_creator
from langflow.interface.tools.base import tool_creator
from langflow.interface.wrappers.base import wrapper_creator
from langflow.utils.lazy_load import LazyLoadDictBase

class NodeTypesDict(LazyLoadDictBase):
    def __init__(self):
        self._all_types_dict = None

    @property
    def NODE_TYPE_MAP(self):
        return self.all_types_dict

    def _build_dict(self):
        langchain_types_dict = self.get_type_dict()
        return {
            **langchain_types_dict,
            "Custom": ["Custom Tool", "Python Function"],
        }

    def get_custom_component_node_type(self):
        return types.CustomComponentNode

    def get_type_dict(self):
        return {
            **{t: types.PromptNode for t in prompt_creator.to_list()},
            **{t: types.AgentNode for t in agent_creator.to_list()},
            **{t: types.ChainNode for t in chain_creator.to_list()},
            **{t: types.ToolNode for t in tool_creator.to_list()},
            **{t: types.ToolkitNode for t in toolkits_creator.to_list()},
            **{t: types.WrapperNode for t in wrapper_creator.to_list()},
            **{t: types.LLMNode for t in llm_creator.to_list()},
            **{t: types.MemoryNode for t in memory_creator.to_list()},
            **{t: types.EmbeddingNode for t in embedding_creator.to_list()},
            **{t: types.DocumentLoaderNode for t in documentloader_creator.to_list()},
            **{t: types.TextSplitterNode for t in textsplitter_creator.to_list()},
            **{t: types.OutputParserNode for t in output_parser_creator.to_list()},
            **{t: types.CustomComponentNode for t in custom_component_creator.to_list()},
            **{t: types.RetrieverNode for t in retriever_creator.to_list()},
        }

lazy_load_node_dict = NodeTypesDict()

This change replaces the term vertex with node throughout the code to make it more intuitive and less confusing. Additionally, you should update the imports in src/backend/base/langflow/graph/__init__.py to reflect this change:

from langflow.graph.edge.base import Edge
from langflow.graph.graph.base import Graph
from langflow.graph.node.base import Node
from langflow.graph.node.types import (
    AgentNode,
    ChainNode,
    CustomComponentNode,
    DocumentLoaderNode,
    EmbeddingNode,
    LLMNode,
    MemoryNode,
    PromptNode,
    RetrieverNode,
    TextSplitterNode,
    ToolkitNode,
    ToolNode,
    VectorStoreNode,
    WrapperNode,
)

__all__ = [
    "Graph",
    "Node",
    "Edge",
    "AgentNode",
    "ChainNode",
    "DocumentLoaderNode",
    "EmbeddingNode",
    "LLMNode",
    "MemoryNode",
    "PromptNode",
    "TextSplitterNode",
    "ToolNode",
    "ToolkitNode",
    "VectorStoreNode",
    "WrapperNode",
    "RetrieverNode",
    "CustomComponentNode",
]

Additionally, update the Graph class in src/backend/base/langflow/graph/graph/base.py to replace vertex with node:

class Graph:
    """A class representing a graph of nodes and edges."""

    def __init__(
        self,
        nodes: List[Dict],
        edges: List[Dict[str, str]],
        flow_id: Optional[str] = None,
        user_id: Optional[str] = None,
    ) -> None:
        """
        Initializes a new instance of the Graph class.

        Args:
            nodes (List[Dict]): A list of dictionaries representing the nodes of the graph.
            edges (List[Dict[str, str]]): A list of dictionaries representing the edges of the graph.
            flow_id (Optional[str], optional): The ID of the flow. Defaults to None.
        """
        self._nodes = nodes
        self._edges = edges
        self.raw_graph_data = {"nodes": nodes, "edges": edges}
        self._runs = 0
        self._updates = 0
        self.flow_id = flow_id
        self.user_id = user_id
        self._is_input_nodes: List[str] = []
        self._is_output_nodes: List[str] = []
        self._is_state_nodes: List[str] = []
        self._has_session_id_nodes: List[str] = []
        self._sorted_nodes_layers: List[List[str]] = []
        self._run_id = ""

        self.top_level_nodes = []
        for node in self._nodes:
            if node_id := node.get("id"):
                self.top_level_nodes.append(node_id)
        self._graph_data = process_flow(self.raw_graph_data)

        self._nodes = self._graph_data["nodes"]
        self._edges = self._graph_data["edges"]
        self.inactivated_nodes: set = set()
        self.activated_nodes: List[str] = []
        self.nodes_layers: List[List[str]] = []
        self.nodes_to_run: set[str] = set()
        self.stop_node: Optional[str] = None
        self.inactive_nodes: set = set()
        self.edges: List[ContractEdge] = []
        self.nodes: List[Node] = []
        self.run_manager = RunnableNodesManager()
        self._build_graph()
        self.build_graph_maps(self.edges)
        self.define_nodes_lists()
        self.state_manager = GraphStateManager()

    # ... (rest of the class implementation)

This ensures that the terminology is consistent and clear throughout the codebase [1][2][3][4][5].

To continue talking to Dosu, mention @dosu.

from langflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.