refactor: Update ChatOutput to use MultilineInput for text input

Update the ChatOutput class in ChatOutput.py to use the MultilineInput class from the langflow library for text input. This change improves the usability and flexibility of the component, allowing for multiline messages to be passed as output.
This commit is contained in:
ogabrielluiz 2024-06-12 23:50:49 -03:00
commit 72649a034a
2 changed files with 4 additions and 14 deletions

View file

@ -1,6 +1,5 @@
from langflow.base.io.chat import ChatComponent
from langflow.field_typing import Text
from langflow.inputs import BoolInput, DropdownInput, StrInput
from langflow.inputs import BoolInput, DropdownInput, MultilineInput, StrInput
from langflow.schema.message import Message
from langflow.template import Output
@ -11,10 +10,9 @@ class ChatOutput(ChatComponent):
icon = "ChatOutput"
inputs = [
StrInput(
MultilineInput(
name="input_value",
display_name="Text",
multiline=True,
info="Message to be passed as output.",
input_types=["Text", "Message"],
),
@ -37,17 +35,9 @@ class ChatOutput(ChatComponent):
),
]
outputs = [
Output(display_name="Text", name="text", method="text_response"),
Output(display_name="Message", name="message", method="message_response"),
]
def text_response(self) -> Text:
result = self.input_value
if self.session_id:
self.message_response()
self.status = result
return result
def message_response(self) -> Message:
message = Message(
text=self.input_value,
@ -57,7 +47,5 @@ class ChatOutput(ChatComponent):
)
if self.session_id and isinstance(message, Message) and isinstance(message.text, str):
self.store_message(message)
self.message.value = message
self.status = message
return message

View file

@ -9,6 +9,7 @@ from .inputs import (
PromptInput,
SecretStrInput,
StrInput,
MultilineInput,
)
__all__ = [
@ -22,4 +23,5 @@ __all__ = [
"DropdownInput",
"FileInput",
"PromptInput",
"MultilineInput",
]