Update CombineTextComponent to concatenate two text sources

This commit is contained in:
Rodrigo Nader 2024-03-30 16:53:58 -03:00
commit e564991040

View file

@ -1,25 +1,28 @@
from langflow.interface.custom.custom_component import CustomComponent from langflow.interface.custom.custom_component import CustomComponent
from langflow.field_typing import Text from langflow.field_typing import Text
class CombineTextComponent(CustomComponent): class CombineTextComponent(CustomComponent):
display_name = "Combine Text" display_name = "Combine Text"
description = "Concatenate multiple text sources into a single text chunk using a specified delimiter." description = "Concatenate two text sources into a single text chunk using a specified delimiter."
icon = "merge" icon = "merge"
def build_config(self): def build_config(self):
return { return {
"texts": { "text1": {
"display_name": "Texts", "display_name": "First Text",
"info": "Multiple text inputs to concatenate.", "info": "The first text input to concatenate.",
},
"text2": {
"display_name": "Second Text",
"info": "The second text input to concatenate.",
}, },
"delimiter": { "delimiter": {
"display_name": "Delimiter", "display_name": "Delimiter",
"info": "A string used to separate each text input. Defaults to a whitespace.", "info": "A string used to separate the two text inputs. Defaults to a whitespace.",
}, },
} }
def build(self, texts: list[str], delimiter: str = " ") -> Text: def build(self, text1: str, text2: str, delimiter: str = " ") -> Text:
combined = delimiter.join(texts) combined = delimiter.join([text1, text2])
self.status = combined self.status = combined
return combined return combined