DxAIChat.AppendMessageAsync(String, ChatRole, List<IAIChatMessageContextItem>) Method
Adds a message to the chat history.
Namespace: DevExpress.AIIntegration.Blazor.Chat
Assembly: DevExpress.AIIntegration.Blazor.Chat.v26.1.dll
Declaration
public Task AppendMessageAsync(
string messageContent,
ChatRole role,
List<IAIChatMessageContextItem> contexts = null
)
Parameters
| Name | Type | Description |
|---|---|---|
| messageContent | String | The message text. |
| role | Microsoft.Extensions.AI.ChatRole | The intended purpose of the message within a chat interaction. |
Optional Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| contexts | List<IAIChatMessageContextItem> | null | A collection of context items associated with the message. |
Returns
| Type | Description |
|---|---|
| Task | The task completed when the message is added. |
Remarks
Call the AppendMessageAsync method to add a message to the chat history without sending it to the AI service. Use this method in the MessageSending event to append a system prompt or supplemental context.
The following code snippet adds a system instruction to the chat:
<DxAIChat MessageSending="OnMessageSending" />
@code {
private async Task OnMessageSending(MessageSendingEventArgs args) {
await args.Chat.AppendMessageAsync("Translate text to Spanish", ChatRole.System);
}
}
To programmatically send a message to the AI service, use the SendMessageAsync method.
See Also