Inputs
Input and output components define where data enters and exits your flow.
Both Text Input and Chat Input components accept user input and return a Message
object, but they serve different purposes.
The Text Input component accepts a text string input and returns a Message
object containing only the input text. The output does not appear in the Playground.
The Chat Input component accepts multiple input types including text, files, and metadata, and returns a Message
object containing the text along with sender information, session ID, and file attachments.
The Chat Input component provides an interactive chat interface in the Playground.
Chat input
This component collects user input as Text
strings from the chat and wraps it in a Message
object that includes the input text, sender information, session ID, file attachments.
It can optionally store the message in a chat history.
Parameters
Name | Display Name | Info |
---|---|---|
background_color |
Background Color |
The background color of the icon. |
chat_icon |
Icon |
The icon of the message. |
files |
Files |
Files to be sent with the message. |
input_value |
Text |
The message to be passed as input. Accepts text, data objects, messages, and dataframes. |
sender |
Sender Type |
The type of sender. |
sender_name |
Sender Name |
The name of the sender. |
session_id |
Session ID |
The session ID of the chat. If empty, the current session_id parameter is used. |
should_store_message |
Store Messages |
Store the message in the history. |
text_color |
Text Color |
The text color of the name. |
Name | Display Name | Info |
---|---|---|
message |
Message |
The response message. |
Message method
The ChatInput
class provides an asynchronous method to create and store a Message
object based on the input parameters.
The Message
object is created in the message_response
method of the ChatInput
class using the Message.create()
factory method.
The user’s input is stored in the input_value
field of the Message
object.
message = await Message.create(
text=self.input_value,
sender=self.sender,
sender_name=self.sender_name,
session_id=self.session_id,
files=self.files,
properties={
"background_color": background_color,
"text_color": text_color,
"icon": icon,
},
)
Component code
chat.py
from langflow.base.data.utils import IMG_FILE_TYPES, TEXT_FILE_TYPES
from langflow.base.io.chat import ChatComponent
from langflow.inputs import BoolInput
from langflow.io import (
DropdownInput,
FileInput,
MessageTextInput,
MultilineInput,
Output,
)
from langflow.schema.message import Message
from langflow.utils.constants import (
MESSAGE_SENDER_AI,
MESSAGE_SENDER_NAME_USER,
MESSAGE_SENDER_USER,
)
class ChatInput(ChatComponent):
display_name = "Chat Input"
description = "Get chat inputs from the Playground."
icon = "MessagesSquare"
name = "ChatInput"
minimized = True
inputs = [
MultilineInput(
name="input_value",
display_name="Text",
value="",
info="Message to be passed as input.",
input_types=[],
),
BoolInput(
name="should_store_message",
display_name="Store Messages",
info="Store the message in the history.",
value=True,
advanced=True,
),
DropdownInput(
name="sender",
display_name="Sender Type",
options=[MESSAGE_SENDER_AI, MESSAGE_SENDER_USER],
value=MESSAGE_SENDER_USER,
info="Type of sender.",
advanced=True,
),
MessageTextInput(
name="sender_name",
display_name="Sender Name",
info="Name of the sender.",
value=MESSAGE_SENDER_NAME_USER,
advanced=True,
),
MessageTextInput(
name="session_id",
display_name="Session ID",
info="The session ID of the chat. If empty, the current session ID parameter will be used.",
advanced=True,
),
FileInput(
name="files",
display_name="Files",
file_types=TEXT_FILE_TYPES + IMG_FILE_TYPES,
info="Files to be sent with the message.",
advanced=True,
is_list=True,
),
MessageTextInput(
name="background_color",
display_name="Background Color",
info="The background color of the icon.",
advanced=True,
),
MessageTextInput(
name="chat_icon",
display_name="Icon",
info="The icon of the message.",
advanced=True,
),
MessageTextInput(
name="text_color",
display_name="Text Color",
info="The text color of the name",
advanced=True,
),
]
outputs = [
Output(display_name="Message", name="message", method="message_response"),
]
async def message_response(self) -> Message:
background_color = self.background_color
text_color = self.text_color
icon = self.chat_icon
message = await Message.create(
text=self.input_value,
sender=self.sender,
sender_name=self.sender_name,
session_id=self.session_id,
files=self.files,
properties={
"background_color": background_color,
"text_color": text_color,
"icon": icon,
},
)
if self.session_id and isinstance(message, Message) and self.should_store_message:
stored_message = await self.send_message(
message,
)
self.message.value = stored_message
message = stored_message
self.status = message
return message
Text Input
The Text Input component accepts a text string input and returns a Message
object containing only the input text.
The output does not appear in the Playground.
Parameters
Name | Display Name | Info |
---|---|---|
input_value |
Text |
The text to be passed as input. |
Name | Display Name | Info |
---|---|---|
text |
Text |
The response message containing the input text. |
Component code
text.py
from langflow.base.io.text import TextComponent
from langflow.io import MultilineInput, Output
from langflow.schema.message import Message
class TextInputComponent(TextComponent):
display_name = "Text Input"
description = "Get text inputs from the Playground."
icon = "type"
name = "TextInput"
inputs = [
MultilineInput(
name="input_value",
display_name="Text",
info="Text to be passed as input.",
),
]
outputs = [
Output(display_name="Message", name="text", method="text_response"),
]
def text_response(self) -> Message:
return Message(
text=self.input_value,
)