From cd5cba112e1f30678628fcdd33f7d8c744710cea Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Wed, 12 Jun 2024 16:17:57 -0300 Subject: [PATCH] refactor: Update Template class fields and serialization Update the Template class in base.py to include a serialization alias for the type_name field and use the InputTypes class for the fields list. This refactor improves the organization and maintainability of the codebase by providing clearer field definitions and serialization behavior. --- src/backend/base/langflow/template/template/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/base/langflow/template/template/base.py b/src/backend/base/langflow/template/template/base.py index c706f6c80..72eb53fc2 100644 --- a/src/backend/base/langflow/template/template/base.py +++ b/src/backend/base/langflow/template/template/base.py @@ -1,15 +1,15 @@ from typing import Callable, Union -from pydantic import BaseModel, model_serializer +from pydantic import BaseModel, Field, model_serializer -from langflow.inputs.input_mixin import BaseInputMixin +from langflow.inputs.inputs import InputTypes from langflow.template.field.base import Input from langflow.utils.constants import DIRECT_TYPES class Template(BaseModel): - type_name: str - fields: list[Input | BaseInputMixin] + type_name: str = Field(serialization_alias="_type") + fields: list[Input | InputTypes] def process_fields( self, @@ -30,7 +30,7 @@ class Template(BaseModel): result = handler(self) for field in self.fields: result[field.name] = field.model_dump(by_alias=True, exclude_none=True) - result["_type"] = result.pop("type_name") + return result # For backwards compatibility