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

    The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AppendMessageAsync(String, ChatRole, List<IAIChatMessageContextItem>) method.

    Note

    The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

    See Also