diff --git a/src/backend/base/langflow/base/io/text.py b/src/backend/base/langflow/base/io/text.py index 5b1a6678b..93ccac528 100644 --- a/src/backend/base/langflow/base/io/text.py +++ b/src/backend/base/langflow/base/io/text.py @@ -12,16 +12,29 @@ class TextComponent(CustomComponent): def build_config(self): return { - "input_value": {"display_name": "Value", "input_types": ["Record"], "info": "Text or Record to be passed."}, - "record_template": {"display_name": "Record Template", "multiline": True}, + "input_value": { + "display_name": "Value", + "input_types": ["Text", "Record"], + "info": "Text or Record to be passed.", + }, + "record_template": { + "display_name": "Record Template", + "multiline": True, + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "advanced": True, + }, } def build( self, input_value: Optional[Union[Text, Record]] = "", - record_template: Optional[str] = "Text: {text}\nData: {data}", + record_template: Optional[str] = "{text}", ) -> Text: if isinstance(input_value, Record): + if record_template == "": + # it should be dynamically set to the Record's .text_key value + # meaning, if text_key = "bacon", then record_template = "{bacon}" + record_template = "{" + input_value.text_key + "}" input_value = records_to_text(template=record_template, records=input_value) self.status = input_value if not input_value: diff --git a/src/backend/base/langflow/components/inputs/TextInput.py b/src/backend/base/langflow/components/inputs/TextInput.py index 3db9777c6..dc6d16368 100644 --- a/src/backend/base/langflow/components/inputs/TextInput.py +++ b/src/backend/base/langflow/components/inputs/TextInput.py @@ -13,15 +13,20 @@ class TextInput(TextComponent): return { "input_value": { "display_name": "Value", - "input_types": ["Record"], + "input_types": ["Text", "Record"], "info": "Text or Record to be passed as input.", }, - "record_template": {"display_name": "Record Template", "multiline": True}, + "record_template": { + "display_name": "Record Template", + "multiline": True, + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "advanced": True, + }, } def build( self, input_value: Optional[str] = "", - record_template: Optional[str] = "{text}", + record_template: Optional[str] = "", ) -> Text: return super().build(input_value=input_value, record_template=record_template) diff --git a/src/backend/base/langflow/components/outputs/TextOutput.py b/src/backend/base/langflow/components/outputs/TextOutput.py index b3917966b..d36baa497 100644 --- a/src/backend/base/langflow/components/outputs/TextOutput.py +++ b/src/backend/base/langflow/components/outputs/TextOutput.py @@ -16,8 +16,13 @@ class TextOutput(TextComponent): "input_types": ["Record"], "info": "Text or Record to be passed as output.", }, - "record_template": {"display_name": "Record Template", "multiline": True}, + "record_template": { + "display_name": "Record Template", + "multiline": True, + "info": "Template to convert Record to Text. If left empty, it will be dynamically set to the Record's text key.", + "advanced": True, + }, } - def build(self, input_value: Optional[Text] = "", record_template: str = "{text}") -> Text: + def build(self, input_value: Optional[Text] = "", record_template: str = "") -> Text: return super().build(input_value=input_value, record_template=record_template)