From 0e7a1e75e4f29a4b15d00b0624be60ad4fa6bcc6 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 11 Dec 2023 17:05:24 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20exclude=20format?= =?UTF-8?q?=5Ftemplate=20field=20from=20serialization=20to=20prevent=20it?= =?UTF-8?q?=20from=20being=20included=20in=20the=20serialized=20output=20?= =?UTF-8?q?=E2=9C=A8=20feat(base.py):=20add=20format=5Ftemplate=20field=20?= =?UTF-8?q?to=20FrontendNode=20class=20to=20control=20whether=20the=20temp?= =?UTF-8?q?late=20should=20be=20formatted=20or=20not=20during=20serializat?= =?UTF-8?q?ion=20=F0=9F=90=9B=20fix(custom=5Fcomponents.py):=20exclude=20f?= =?UTF-8?q?ormat=5Ftemplate=20field=20from=20serialization=20to=20prevent?= =?UTF-8?q?=20it=20from=20being=20included=20in=20the=20serialized=20outpu?= =?UTF-8?q?t=20=E2=9C=A8=20feat(custom=5Fcomponents.py):=20add=20format=5F?= =?UTF-8?q?template=20field=20to=20CustomComponentFrontendNode=20class=20t?= =?UTF-8?q?o=20control=20whether=20the=20template=20should=20be=20formatte?= =?UTF-8?q?d=20or=20not=20during=20serialization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/template/frontend_node/base.py | 4 +++- .../langflow/template/frontend_node/custom_components.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/template/frontend_node/base.py b/src/backend/langflow/template/frontend_node/base.py index 92c748dca..ce1fe79a0 100644 --- a/src/backend/langflow/template/frontend_node/base.py +++ b/src/backend/langflow/template/frontend_node/base.py @@ -40,6 +40,7 @@ class FieldFormatters(BaseModel): class FrontendNode(BaseModel): + format_template: bool = Field(default=True, exclude=True) template: Template description: Optional[str] = None base_classes: List[str] @@ -80,7 +81,8 @@ class FrontendNode(BaseModel): def serialize_model(self, handler): result = handler(self) if hasattr(self, "template") and hasattr(self.template, "to_dict"): - result["template"] = self.template.to_dict(self.format_field) + format_func = self.format_field if self.format_template else None + result["template"] = self.template.to_dict(format_func) name = result.pop("name") return {name: result} diff --git a/src/backend/langflow/template/frontend_node/custom_components.py b/src/backend/langflow/template/frontend_node/custom_components.py index 75019f85e..c9f80beae 100644 --- a/src/backend/langflow/template/frontend_node/custom_components.py +++ b/src/backend/langflow/template/frontend_node/custom_components.py @@ -1,5 +1,7 @@ from typing import Optional +from pydantic import Field + from langflow.template.field.base import TemplateField from langflow.template.frontend_node.base import FrontendNode from langflow.template.template.base import Template @@ -45,6 +47,7 @@ class Component(CustomComponent): class CustomComponentFrontendNode(FrontendNode): + format_template: bool = Field(default=False, exclude=True) name: str = "CustomComponent" display_name: Optional[str] = "CustomComponent" beta: bool = True