blazor-devexpress-dot-aiintegration-dot-blazor-dot-chat-96d4a46e.md
Defines a user-selectable context for a chat session.
Namespace : DevExpress.AIIntegration.Blazor.Chat
Assembly : DevExpress.AIIntegration.Blazor.Chat.v25.2.dll
NuGet Package : DevExpress.AIIntegration.Blazor.Chat
public class AIChatResource
Use AIChatResource to define a reusable, named chat context that users can select in the AI Chat UI. The resource establishes the conversation environment: defines the assistant role, adds instructions, and attaches a dataset (including binary content). When a user selects the resource, its context applies to the active chat session and guides subsequent AI responses.
Note
A binary resource is processed only if the configured AI provider and model support it.
The following code snippet binds three files as AI chat resources to the DxAIChat control:
<DxAIChat Resources="Resources" />
@code {
List<AIChatResource> Resources { get; set; } = [];
protected override async Task OnInitializedAsync() {
AIChatResource instructions = await FileResourceProvider.GetTextResourceAsync("instructions",
"Technical Support",
"An assistant that helps troubleshoot technical issues and provides step-by-step solutions.");
AIChatResource documentation = await FileResourceProvider.GetTextResourceAsync("ai-chat-doc.md",
"API Reference",
"DevExpress Blazor AI Chat API Reference.");
AIChatResource screenshot = await FileResourceProvider.GetBinaryResourceAsync("ai-chat-image.png",
"AI Chat Screenshot",
"An annotated screenshot of the AI Chat component.",
"image/png");
Resources.Add(instructions);
Resources.Add(documentation);
Resources.Add(screenshot);
await base.OnInitializedAsync();
}
}
You are a Tier-2 Technical Support Specialist. Maintain a helpful, patient, and professional tone.
If the API Reference contains the answer, quote the text directly with minimal modification.
If the user’s query is vague, ask clarifying questions to gather context before proposing a solution.
DevExpress Blazor AI Chat - API Reference
DevExpress AI APIs leverage the Microsoft.Extensions.AI libraries for integration and interoperability with a wide range of AI services. These libraries establish a unified C# abstraction layer for standardized interaction with language models.
The Microsoft.Extensions.AI framework allows developers to integrate support for AI language models and services without modifying the core library. This means you can leverage third-party libraries for new AI providers or create your own custom implementation for in-house language models.
Prerequisites
public static class FileResourceProvider
{
public static async Task<AIChatResource> GetTextResourceAsync(string resourceFileName,
string title,
string description) {
string filePath = GetResourcePath(resourceFileName);
string fileContent = await File.ReadAllTextAsync(filePath);
string mime = Path.GetExtension(resourceFileName).ToLower() switch {
".md" => "text/markdown",
".html" => "text/html",
_ => "text/plain"
};
AIChatResource resource = new AIChatResource(resourceFileName,
title,
fileContent,
mime,
description);
return resource;
}
public static async Task<AIChatResource> GetBinaryResourceAsync(string resourceFileName,
string title,
string description,
string mime) {
string filePath = GetResourcePath(resourceFileName);
byte[] fileContent = await File.ReadAllBytesAsync(filePath);
AIChatResource resource = new AIChatResource(resourceFileName,
title,
fileContent,
mime,
description);
return resource;
}
private static string GetResourcePath(string resourceFileName) =>
Path.Combine(AppContext.BaseDirectory, "AiResources", resourceFileName);
}
Object AIChatResource
See Also