blazor-devexpress-dot-aiintegration-dot-blazor-dot-chat-dot-aichatresource.md
Defines a delegate that returns AI resource content for a chat.
Namespace : DevExpress.AIIntegration.Blazor.Chat
Assembly : DevExpress.AIIntegration.Blazor.Chat.v25.2.dll
NuGet Package : DevExpress.AIIntegration.Blazor.Chat
public delegate Task<IList<AIContent>> AIContentProvider(
AIChatResource resource,
CancellationToken ct
);
| Name | Type | Description |
|---|---|---|
| resource | AIChatResource |
AI Chat resource.
| | ct | CancellationToken |
A cancellation token that cancels the content retrieval operation.
|
| Type | Description |
|---|---|
| Task<IList<Microsoft.Extensions.AI.AIContent>> |
A task that returns a list of AIContent items supplied to the chat.
|
Use the AIContentProvider delegate to supply AIContent items to a chat. The delegate runs when the chat needs input generated from the associated AIChatResource (for example, text fragments or files).
The following code snippet assigns a custom content provider to supply assistant input:
@using ModelContextProtocol
@using ModelContextProtocol.Client
@inject NavigationManager NavigationManager
<DxAIChat Resources="Resources" />
@code{
IEnumerable<AIChatResource> Resources { get; set; } = [];
IMcpClient McpClient { get; set; }
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
await LoadMcpResources();
}
async Task LoadMcpResources() {
var transport = new SseClientTransport(new() { Endpoint = new(NavigationManager.BaseUri + "mcp") });
McpClient = await McpClientFactory.CreateAsync(transport);
var mcpResources = await McpClient.ListResourcesAsync();
Resources = mcpResources.Select(x =>
new AIChatResource(x.Uri, x.Name, LoadResourceData, x.MimeType, x.Description)
);
}
async Task<IList<AIContent>> LoadResourceData(AIChatResource resource, CancellationToken ct) {
var readResource = await McpClient.ReadResourceAsync(resource.Uri, ct);
return readResource.Contents.ToAIContents();
}
}
See Also