From 9cf6e93fe58c80702e7780b6e7ed7cb70a621464 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 1 Dec 2023 17:54:27 -0300 Subject: [PATCH] Add utility functions for API and component validation --- src/backend/langflow/api/utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/backend/langflow/api/utils.py b/src/backend/langflow/api/utils.py index 832cf6b89..250abccf7 100644 --- a/src/backend/langflow/api/utils.py +++ b/src/backend/langflow/api/utils.py @@ -1,3 +1,10 @@ + +from typing import TYPE_CHECKING, List + +if TYPE_CHECKING: + from langflow.services.database.models.flow.model import Flow + + API_WORDS = ["api", "key", "token"] @@ -75,3 +82,22 @@ def update_frontend_node_with_template_values(frontend_node, raw_template_data): frontend_template[key]["value"] = value return frontend_node + +def validate_is_component(flows: List["Flow"]): + + for flow in flows: + if not flow.data or flow.is_component is not None: + continue + + is_component = get_is_component_from_data(flow.data) + if is_component is not None: + flow.is_component = is_component + else: + flow.is_component = len(flow.data.get("nodes", [])) == 1 + return flows + + + +def get_is_component_from_data(data: dict): + """Returns True if the data is a component.""" + return data.get("is_component") \ No newline at end of file