mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 23:04:14 +08:00
* version-1.9.0-docs * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
146 lines
7.3 KiB
Plaintext
146 lines
7.3 KiB
Plaintext
---
|
|
title: Chat Input and Output
|
|
slug: /chat-input-and-output
|
|
---
|
|
|
|
import Icon from "@site/src/components/icon";
|
|
import PartialParams from '@site/docs/_partial-hidden-params.mdx';
|
|
|
|
:::warning
|
|
**Chat Input and Output** components are required to chat with your flow in the **Playground**.
|
|
For more information, see [Test flows in the Playground](/concepts-playground).
|
|
:::
|
|
|
|
**Chat Input and Output** components are designed to handle conversational interactions in Langflow.
|
|
|
|
## Chat Input
|
|
|
|
The **Chat Input** component accepts text and file input, such as a chat message or a file.
|
|
This data is passed to other components as [`Message` data](/data-types) containing the provided input as well as associated chat metadata, such as the sender, session ID, timestamp, and file attachments.
|
|
|
|
Initial input should _not_ be provided as a complete `Message` object because the **Chat Input** component constructs the `Message` object that is then passed to other components in the flow.
|
|
|
|
### Chat Input parameters
|
|
|
|
<PartialParams />
|
|
|
|
| Name | Display Name | Info |
|
|
|------|--------------|------|
|
|
|input_value|Input Text| Input parameter. The message text string to be passed as input. |
|
|
|sender|Sender Type| Input parameter. Identifies the sender as either `User` or `Language Model`.|
|
|
|sender_name|Sender Name| Input parameter. The name of the sender. If unspecified, defaults to `User` or `Language Model`. |
|
|
|session_id|Session ID| Input parameter. The unique identifier for the chat session. If empty, the current session ID parameter is used.|
|
|
|files|Files| Input parameter. The files to be sent with the message.|
|
|
|background_color|Background Color| Input parameter. The background color of the icon.|
|
|
|chat_icon|Icon| Input parameter. The icon of the message.|
|
|
|should_store_message|Store Messages| Input parameter. Whether to store the message in chat history.|
|
|
|text_color|Text Color| Input parameter. The text color of the name.|
|
|
|
|
For information about the resulting `Message` object, including input parameters that are directly mapped to `Message` attributes, see [`Message` data](/data-types#message).
|
|
|
|
<details>
|
|
<summary>Message method for Chat Input</summary>
|
|
|
|
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.
|
|
|
|
```python
|
|
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,
|
|
},
|
|
)
|
|
```
|
|
|
|
</details>
|
|
|
|
## Chat Output
|
|
|
|
The **Chat Output** component ingests `Message`, `JSON`, or `Table` data from other components, transforms it into `Message` data if needed, and then emits the final output as a chat message.
|
|
For information about these data types, see [Use Langflow data types](/data-types).
|
|
|
|
In the **Playground**, chat output is limited to the parts of the `Message` object that are relevant to the chat interface, such as the text response, sender name, and file attachments.
|
|
To see the metadata associated with a chat message, inspect the message logs in the **Playground**.
|
|
|
|
When using the Langflow API, the API response includes the **Chat Output** `Message` object along with other response data from the flow run.
|
|
Langflow API responses can be extremely verbose, so your applications must include code to extract relevant data from the response to return to the user.
|
|
For an example, see the [Langflow quickstart](/get-started-quickstart).
|
|
|
|
### Chat Output parameters
|
|
|
|
<PartialParams />
|
|
|
|
| Name | Display Name | Info |
|
|
|------|--------------|------|
|
|
|input_value|Inputs| Input parameter. The message text string to be passed as output. |
|
|
|should_store_message|Store Messages| Input parameter. Whether to store the message in chat history.|
|
|
|sender|Sender Type| Input parameter. Identifies the sender as either `User` or `Language Model`.|
|
|
|sender_name|Sender Name| Input parameter. The name of the sender. If unspecified, defaults to `User` or `Language Model`. |
|
|
|session_id|Session ID| Input parameter. The unique identifier for the chat session. If empty, the current session ID parameter is used.|
|
|
|data_template|Data Template| Input parameter. The template to convert [`JSON` input](/data-types#json) to `text`. If empty, it is dynamically set to the `JSON` object's `text` key.|
|
|
|background_color|Background Color| Input parameter. The background color of the icon.|
|
|
|chat_icon|Icon| Input parameter. The icon of the message.|
|
|
|text_color|Text Color| Input parameter. The text color of the name.|
|
|
|clean_data|Basic Clean Data| Input parameter. When enabled, [`Table` input](/data-types#table) is cleaned when converted to text. Cleaning removes empty rows, empty lines in cells, and multiple newlines.|
|
|
|
|
For information about the resulting `Message` object, including input parameters that are directly mapped to `Message` attributes, see [`Message` data](/data-types#message).
|
|
|
|
## Use Chat Input and Output components in a flow
|
|
|
|
To use the **Chat Input** and **Chat Output** components in a flow, connect them to components that accept or emit [`Message` data](/data-types#message).
|
|
|
|
For example, the following flow connects **Chat Input** and **Chat Output** to a **Language Model** component, creating a simple LLM-based chat flow.
|
|
|
|

|
|
|
|
:::tip
|
|
For detailed examples of **Chat Input and Output** components in flows, see the following:
|
|
|
|
* [Langflow quickstart](/get-started-quickstart): Create and run a basic agent flow.
|
|
* **Basic Prompting** template: Create an LLM-based chat flow that accepts chat input as well as a prompt with additional instructions for the LLM. Many other Langflow templates also use **Chat Input and Output** components.
|
|
* [Connect applications to agents](/agent-tutorial): Explore more advanced concepts around agent flows and prompting, including triggering agent flows from external applications.
|
|
:::
|
|
|
|
### Send chat input with the Langflow API
|
|
|
|
You can use the Langflow API to run a flow by sending input to a **Chat Input** component:
|
|
|
|
```bash
|
|
curl --request POST \
|
|
--url "http://$LANGFLOW_SERVER_ADDRESS/api/v1/run/$FLOW_ID" \
|
|
--header "Content-Type: application/json" \
|
|
--header "x-api-key: $LANGFLOW_API_KEY" \
|
|
--data '{
|
|
"input_value": "What's the recommended way to install Docker on Mac M1?",
|
|
"output_type": "chat",
|
|
"input_type": "chat"
|
|
}'
|
|
```
|
|
|
|
When triggering flows with the Langflow API, the payload must contain the values for the **Chat Input** component's input parameters, such as `input_value`.
|
|
|
|
Not all parameters need to be specified in the request.
|
|
For example, `session_id` uses the flow's default session ID if omitted.
|
|
If you want to use a custom session ID, include `session_id` in your request:
|
|
|
|
```bash
|
|
curl --request POST \
|
|
--url "http://$LANGFLOW_SERVER_ADDRESS/api/v1/run/$FLOW_ID" \
|
|
--header "Content-Type: application/json" \
|
|
--header "x-api-key: $LANGFLOW_API_KEY" \
|
|
--data '{
|
|
"input_value": "Whats the recommended way to install Docker on Mac M1",
|
|
"session_id": "$USER_ID",
|
|
"output_type": "chat",
|
|
"input_type": "chat"
|
|
}'
|
|
```
|
|
|
|
For more information, see [Trigger flows with the Langflow API](/concepts-publish). |