Plus · Chat
Chat
Used to quickly build conversation content

When to use

The Chat component can be used in scenarios such as regular conversations or AI conversations.
The rendering of the conversation content is based on the MarkdownRender component, which supports Markdown and MDX. It allows for common rich text features such as images, tables, links, bold text, code blocks, and more. More complex and customized document writing and display requirements can be achieved using JSX.

Demos

How to import

Chat is supported starting from version v2.63.0.

Basic usage

By setting chats, onChatsChange, and onMessageSend, you can achieve basic conversation display and interaction.
Conversations involve multiple participants and multiple rounds of interaction. Role information, including names and avatars, can be passed through the roleConfig parameter. For detailed parameter information, refer to RoleConfig.
The prompt text of the upload button can be set through uploadTipProps. For details, please refer to Tooltip.
Dialogue is a scene involving multiple parties and multiple rounds of interaction. Role information (including name, avatar, etc.) can be passed in through roleConfig, and the specific parameter details are RoleConfig.
Use the align attribute to set the alignment of the dialog, supporting left and right alignment (leftRight, default) and left alignment (leftAlign).

Chat status

The chats type is Message[], where each Message contains various information about the conversation, such as role, content, attachment, status, unique identifier (id), creation time (createAt), and more. For detailed information, please refer to Message. The conversation style may vary depending on the different status values.

Dynamic update chats

For the case of receiving Server-Sent Event data from the backend, the obtained data can be used to update the chats, and the conversation content will be updated in real-time.
The showStopGenerate parameter can be used to determine whether to display the stop generation button, with a default value of false. The logic for stopping the generation can be handled in the onStopGenerator function.

Clear context

Displaying the clear context button in the input box can be enabled through showClearContext, which defaults to false. The context can also be cleared by calling the clearContext method through ref.

Custom rendering dialog box

Pass in custom rendering configuration through chatBoxRenderConfig, the chatBoxRenderConfig type is as follows
Custom render avatar and Title through renderChatBoxAvatar and renderChatBoxTitle
When hovering over a conversation, the conversation action area will be displayed. You can customize the rendering of the action area using renderChatBoxAction.
You can customize the content of the action area using renderChatBoxContent.
Use renderFullChatBox to custom render the entire chat box

Custom render InputArea

The rendering input box can be customized through renderInputArea, the parameters are as follows
Example of detailProps
Other Example:

Hint

The prompt area content can be set through hints. After clicking the prompt content, the prompt content will become the new user input content and trigger the onHintClick callback.

Custom render Hint

Customize the content of the prompt area through renderHintBox, the parameters are as follows
Example:

API

PROPERTIESINSTRUCTIONSTYPEDEFAULT
alignDialog alignment, supports leftRight,leftAlignstringleftRight
bottomSlotbottom slot for chatReact.ReactNode-
chatBoxRenderConfigchatBox rendering configurationChatBoxRenderConfig-
chatsControlled conversation listMessage-
classNameCustom class namestring-
customMarkDownComponentscustom markdown render, transparently passed to MarkdownRender for conversation content renderingMDXProps['components']-
hintsprompt informationstring-
hintClshint stylestring-
hintStylehint styleCSSProperties-
inputBoxStyleInput box styleCSSProperties-
inputBoxClsInput box classNamestring-
sendHotKeyKeyboard shortcut for sending content, supports enter | shift+enter. The former will send the message in the input box when you press enter alone. When the shift and enter keys are pressed at the same time, it will only wrap the line and not send it. The latter is the oppositestringenter
modeConversation mode, support bubble | noBubble | userBubblestringbubble
roleConfigRole information configuration, seeRoleConfigRoleConfig-
renderDividerCustom render divider, supported since v2.67.0(message?: Message) => ReactNode-
renderHintBoxCustom rendering prompt information(props: {content: string; index: number,onHintClick: () => void}) => React.ReactNode-
onChatsChangeTriggered when the conversation list changes(chats: Message[]) => void-
onClearTriggered when context message is cleared() => void-
onHintClickTriggered when the prompt message is clicked(hint: string) => void-
onInputChangeTriggered when input area information changes(props: { value?: string, attachment?: FileItem[] }) => void;-
onMessageBadFeedbackTriggered when the message is negatively fed back(message: Message) => void-
onMessageCopyTriggered when copying a message(message: Message) => void-
onMessageDeleteTriggered when a message is deleted(message: Message) => void-
onMessageGoodFeedbackTriggered when the message is fed back positively(message: Message) => void-
onMessageResetTriggered when message is reset(message: Message) => void-
onMessageSendTriggered when sending a message(content: string, attachment?: FileItem[]) => void-
onStopGeneratorFires when the stop generation button is clicked(message: Message) => void-
placeholderInput box placeholderstring-
renderInputAreaCustom rendering input box(props: RenderInputAreaProps) => React.ReactNode-
showClearContextWhether to display the clear context buttonbooleanfalse
showStopGenerateWhether to display the stop generation buttonbooleanfalse
topSlottop slot for chatReact.ReactNode-
uploadPropsUpload component properties, refer to details UploadUploadProps-
uploadTipPropsUpload component prompt attribute, refer to details TooltipTooltipProps-

RoleConfig

PROPERTIESINSTRUCTIONSTYPEDEFAULT
userUser informationMetadata-
assistantAssistant informationMetadata-
systemSystem informationMetadata-

Metadata

PROPERTIESINSTRUCTIONSTYPEDEFAULT
namenamestring-
avataravatarstring-
colorAvatar background color, same as the color parameter of Avatar component, support amberbluecyangreengreyindigolight-bluelight-greenlimeorangepinkpurpleredtealvioletyellowstringgrey

Message

PROPERTIESINSTRUCTIONSTYPEDEFAULT
rolerolestring-
namenamestring-
idUniquely identifiesstring| number-
contentall contentstringContent[]
parentIdparent Uniquely identifiesstring-
createAtcreation timenumber-
statusInformation status, loading | incomplete | complete | errorstringcomplete

Content

PROPERTIESINSTRUCTIONSTYPEDEFAULT
typetype, suport text | image_url | file_urlstring-
textContent data when type is textstring-
image_urlContent data when type is image_url{ url: string }-
file_urlContent data when type is file_url{ url: string; name: string; size: string; type: string }-

Methods

METHODINSTRUCTIONS
resetMessageReset message
scrollToBottom(animation: boolean)Scroll to the bottom, if animation is true, there will be animation, otherwise there will be no animation.
clearContextclear context
sendMessage(content: string, attachment: FileItem[])send message with content and attachment

Design Token