Back to Devexpress

IAIChat.SendMessage(String, ChatRole, List<AIChatUploadFileInfo>) Method

blazor-devexpress-dot-aiintegration-dot-blazor-dot-chat-dot-iaichat-dot-sendmessage-x28-string-chatrole-list-aichatuploadfileinfo-x29.md

latest2.4 KB
Original Source

IAIChat.SendMessage(String, ChatRole, List<AIChatUploadFileInfo>) Method

Sends a message to the chat.

Namespace : DevExpress.AIIntegration.Blazor.Chat

Assembly : DevExpress.AIIntegration.Blazor.Chat.v25.2.dll

NuGet Package : DevExpress.AIIntegration.Blazor.Chat

Declaration

csharp
Task SendMessage(
    string messageContent,
    ChatRole role,
    List<AIChatUploadFileInfo> files = null
)

Parameters

NameTypeDescription
messageContentString

The message text to be sent.

| | role | Microsoft.Extensions.AI.ChatRole |

The role of the message owner.

|

Optional Parameters

NameTypeDefaultDescription
filesList<AIChatUploadFileInfo>null

A collection of files to be uploaded.

|

Returns

TypeDescription
Task

A task that is completed when the message is sent.

|

Remarks

Call the SendMessage method to send a message to the chat.

razor
<DxAIChat MessageSent="MessageSent"
          FileUploadEnabled="true" />

@code {
    async Task MessageSent(MessageSentEventArgs args) {
        if(args.Files != null && args.Files.Count > 0) {
            var fileNames = args.Files.Select(x => x.Name);
            var response = $"Processed message content: {args.Content}.{System.Environment.NewLine}";
            response += $"The message contains {args.Files.Count} attached file(s):{System.Environment.NewLine}";
            response += string.Join(System.Environment.NewLine, fileNames);
            await args.Chat.SendMessage(response, ChatRole.Assistant);
        }
    }
}

Run Demo: AI Chat - Manual Message Processing

See Also

IAIChat Interface

IAIChat Members

DevExpress.AIIntegration.Blazor.Chat Namespace