From 25752b1aa8cffc4ecec5b7466e77a78b6e4595a0 Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Thu, 30 May 2024 17:17:36 -0300 Subject: [PATCH] feat: Migrate base classes to outputs in FrontendNode This commit migrates the base classes of the FrontendNode to the outputs field. Each base class is converted into an OutputField with the same name and type. This change ensures consistency and improves the structure of the code. --- .../base/langflow/template/frontend_node/base.py | 13 ++++++++++++- src/frontend/src/utils/reactflowUtils.ts | 10 +++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/backend/base/langflow/template/frontend_node/base.py b/src/backend/base/langflow/template/frontend_node/base.py index 2b3771db9..2d69922cf 100644 --- a/src/backend/base/langflow/template/frontend_node/base.py +++ b/src/backend/base/langflow/template/frontend_node/base.py @@ -4,7 +4,7 @@ from typing import ClassVar, Dict, List, Optional, Union from pydantic import BaseModel, Field, field_serializer, model_serializer -from langflow.template.field.base import InputField +from langflow.template.field.base import InputField, OutputField from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS from langflow.template.frontend_node.formatter import field_formatters from langflow.template.template.base import Template @@ -77,6 +77,8 @@ class FrontendNode(BaseModel): """List of conditional paths for the frontend node.""" frozen: bool = False """Whether the frontend node is frozen.""" + outputs: List[OutputField] = [] + """List of output fields for the frontend node.""" field_order: list[str] = [] """Order of the fields in the frontend node.""" @@ -114,6 +116,15 @@ class FrontendNode(BaseModel): result["template"] = self.template.to_dict(format_func) name = result.pop("name") + # Migrate base classes to outputs + if "output_types" in result: + for base_class in result["output_types"]: + output = OutputField( + name=base_class, + types=[base_class], + ) + result["outputs"].append(output.model_dump()) + return {name: result} # For backwards compatibility diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 963063eff..afb3db57f 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -444,9 +444,13 @@ export function updateNewOutput({ nodes, edges }: updateEdgesHandleIdsType) { !sourceNode.data.node?.outputs || sourceNode.data.node!.outputs!.length === 0 ) { - sourceNode.data.node!.outputs = [ - { types: sourceNode.data.node!.base_classes, selected: selected }, - ]; + const outputTypes = sourceNode.data.node!.output_types; + // create a new output field for each output type + sourceNode.data.node!.outputs = outputTypes?.map((type) => ({ + types: [type], + selected: selected, + name: type, + })); } } edge.sourceHandle = scapedJSONStringfy(newSourceHandle);