chore: Refactor TextComponent to remove unused code and improve readability

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-22 14:19:40 -03:00
commit 7331cb1903

View file

@ -1,9 +1,4 @@
from typing import Optional
from langflow.custom import Component
from langflow.field_typing import Text
from langflow.helpers.data import data_to_text
from langflow.schema import Data
class TextComponent(Component):
@ -24,21 +19,3 @@ class TextComponent(Component):
"advanced": True,
},
}
def build(
self,
input_value: Optional[Text] = "",
data_template: Optional[str] = "{text}",
) -> Text:
if isinstance(input_value, Data):
if data_template == "":
# it should be dynamically set to the Data's .text_key value
# meaning, if text_key = "bacon", then data_template = "{bacon}"
data_template = "{" + input_value.text_key + "}"
input_value = data_to_text(template=data_template, data=input_value)
elif not input_value:
input_value = ""
self.status = input_value
if not input_value:
input_value = ""
return input_value