Skip to main content
All docs
V26.1
  • AIChatControl.AppendMessageAsync(String, ChatRole, List<IAIChatMessageContextItem>) Method

    Adds a message to chat history.

    Namespace: DevExpress.AIIntegration.WinForms.Chat

    Assembly: DevExpress.AIIntegration.WinForms.Chat.v26.1.dll

    NuGet Package: DevExpress.AIIntegration.WinForms.Chat

    Declaration

    public Task AppendMessageAsync(
        string text,
        ChatRole role,
        List<IAIChatMessageContextItem> contexts = null
    )

    Parameters

    Name Type Description
    text 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

    A task that represents the asynchronous operation.

    Remarks

    Call the AppendMessageAsync method to add messages to the chat history without sending a request to the AI service. This approach is useful for system prompts, assistant hints, and supplemental context.

    Example

    The following example adds a system instruction before the control sends the user message:

    using DevExpress.AIIntegration.Blazor.Chat.WebView;
    using Microsoft.Extensions.AI;
    
    public Chat() {
        InitializeComponent();
        aiChatControl1.MessageSending += AiChatControl1_MessageSending;
    }
    
    async void AiChatControl1_MessageSending(object sender, AIChatControlMessageSendingEventArgs e) {
        await e.Chat.AppendMessageAsync("Translate text to Spanish", ChatRole.System);
    }
    

    Refer to the following help topic for additional information: AI Chat Control

    See Also