Back to Devexpress

DxAIChat.Resources Property

blazor-devexpress-dot-aiintegration-dot-blazor-dot-chat-dot-dxaichat-7e4b65a4.md

latest6.9 KB
Original Source

DxAIChat.Resources Property

Specifies AI Chat resources that a user can reference during a chat session.

Namespace : DevExpress.AIIntegration.Blazor.Chat

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

NuGet Package : DevExpress.AIIntegration.Blazor.Chat

Declaration

csharp
[Parameter]
public IEnumerable<AIChatResource> Resources { get; set; }

Property Value

TypeDescription
IEnumerable<AIChatResource>

A collection of AIChatResource objects.

|

Remarks

Use the Resources property to specify files, instructions, and data sources that users can add to a chat session. These contexts (AI resources) help the AI model produce precise, grounded answers and reduce hallucinations.

Each AI resource is defined as an AIChatResource object. When at least one resource is added to Resources, the chat input box displays a picker button.

Note

AI resources are not used automatically. Users must select resources in the picker to attach them to the active chat session.

The following code snippet binds three files in different formats as AI Chat resources:

razor
<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

  • .NET 8.0 or above
  • AI language model (choose one of the following):

csharp
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);
}

Combine AI Resources with File Upload

An AI resource is a predefined, curated AI Chat context. When the FileUploadEnabled property is set to true, a user can also attach any files to a conversation to supply ad‑hoc evidence. Combine both approaches for maximum flexibility.

When Resources is set and FileUploadEnabled is true, the chat input box displays a single control for both a resource picker and file upload.

See Also

DxAIChat Class

DxAIChat Members

DevExpress.AIIntegration.Blazor.Chat Namespace