From fd16f136b121546292ff18e745fcf20166f4f4a8 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 1 Mar 2024 09:19:10 -0300 Subject: [PATCH] Refactor TextInput and TextOutput to use TextComponent --- .../langflow/components/io/TextInput.py | 13 +++---------- .../langflow/components/io/TextOutput.py | 13 +++++-------- .../langflow/components/io/base/text.py | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 src/backend/langflow/components/io/base/text.py diff --git a/src/backend/langflow/components/io/TextInput.py b/src/backend/langflow/components/io/TextInput.py index f8c1ad606..dc7ff1a73 100644 --- a/src/backend/langflow/components/io/TextInput.py +++ b/src/backend/langflow/components/io/TextInput.py @@ -1,19 +1,12 @@ from typing import Optional -from langflow import CustomComponent +from langflow.components.io.base.text import TextComponent from langflow.field_typing import Text -class TextInput(CustomComponent): +class TextInput(TextComponent): display_name = "Text Input" description = "Used to pass text input to the next component." - field_config = { - "input_value": {"display_name": "Value", "multiline": True}, - } - def build(self, input_value: Optional[str] = "") -> Text: - self.status = input_value - if not input_value: - input_value = "" - return input_value + return super().build(input_value=input_value) diff --git a/src/backend/langflow/components/io/TextOutput.py b/src/backend/langflow/components/io/TextOutput.py index d3fd37f66..f92e09146 100644 --- a/src/backend/langflow/components/io/TextOutput.py +++ b/src/backend/langflow/components/io/TextOutput.py @@ -1,19 +1,16 @@ from typing import Optional -from langflow import CustomComponent +from langflow.components.io.base.text import TextComponent from langflow.field_typing import Text -class TextOutput(CustomComponent): +class TextOutput(TextComponent): display_name = "Text Output" description = "Used to pass text output to the next component." field_config = { - "value": {"display_name": "Value"}, + "input_value": {"display_name": "Value"}, } - def build(self, value: Optional[str] = "") -> Text: - self.status = value - if not value: - value = "" - return value + def build(self, input_value: Optional[Text] = "") -> Text: + return super().build(input_value=input_value) diff --git a/src/backend/langflow/components/io/base/text.py b/src/backend/langflow/components/io/base/text.py new file mode 100644 index 000000000..8c6620781 --- /dev/null +++ b/src/backend/langflow/components/io/base/text.py @@ -0,0 +1,19 @@ +from typing import Optional + +from langflow import CustomComponent +from langflow.field_typing import Text + + +class TextComponent(CustomComponent): + display_name = "Text Component" + description = "Used to pass text to the next component." + + field_config = { + "input_value": {"display_name": "Value", "multiline": True}, + } + + def build(self, input_value: Optional[str] = "") -> Text: + self.status = input_value + if not input_value: + input_value = "" + return input_value