refactor: Update TextOperatorComponent to handle default outputs

Update the TextOperatorComponent to handle default outputs when the true_output or false_output is not passed. If not provided, the default output will be the input text. This change improves the flexibility and usability of the component.
This commit is contained in:
Rodrigo 2024-06-13 17:07:41 -03:00
commit 32170a79ae

View file

@ -25,6 +25,7 @@ class TextOperatorComponent(Component):
display_name="Operator", display_name="Operator",
options=["equals", "not equals", "contains", "starts with", "ends with"], options=["equals", "not equals", "contains", "starts with", "ends with"],
info="The operator to apply for comparing the texts.", info="The operator to apply for comparing the texts.",
value="equals",
), ),
BoolInput( BoolInput(
name="case_sensitive", name="case_sensitive",
@ -36,13 +37,13 @@ class TextOperatorComponent(Component):
StrInput( StrInput(
name="true_output", name="true_output",
display_name="True Output", display_name="True Output",
info="The output to return or display when the comparison is true.", info="The output to return or display when the comparison is true. If not passed, defaults to Input Text.",
advanced=True, advanced=True,
), ),
StrInput( StrInput(
name="false_output", name="false_output",
display_name="False Output", display_name="False Output",
info="The output to return or display when the comparison is false.", info="The output to return or display when the comparison is false. If not passed, defaults to Input Text.",
advanced=True, advanced=True,
), ),
] ]
@ -54,11 +55,11 @@ class TextOperatorComponent(Component):
def true_response(self) -> Text: def true_response(self) -> Text:
self.stop("false_result") self.stop("false_result")
return self.true_output or self.input_text return self.true_output
def false_response(self) -> Text: def false_response(self) -> Text:
self.stop("true_result") self.stop("true_result")
return self.false_output or self.input_text return self.false_output
def run(self) -> Text: def run(self) -> Text:
input_text = self.input_text input_text = self.input_text