Skip to main content
All docs
V25.2
  • AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(IChatClient, IAIExceptionHandler, IAIChatClientCustomizeMessageRequest) Method

    Creates a container for AI-powered extensions and registers a chat client in a .NET console application.

    Namespace: DevExpress.AIIntegration

    Assembly: DevExpress.AIIntegration.v25.2.dll

    NuGet Package: DevExpress.AIIntegration

    Declaration

    public static AIExtensionsContainerDefault CreateDefaultAIExtensionContainer(
        IChatClient chatClient,
        IAIExceptionHandler handler = null,
        IAIChatClientCustomizeMessageRequest customizer = null
    )

    Parameters

    Name Type Description
    chatClient Microsoft.Extensions.AI.IChatClient

    A chat client.

    Optional Parameters

    Name Type Default Description
    handler DevExpress.AIIntegration.IAIExceptionHandler null

    An exception handler.

    customizer DevExpress.AIIntegration.IAIChatClientCustomizeMessageRequest null

    Returns

    Type Description
    AIExtensionsContainerDefault

    A container for AI-powered extensions.

    Remarks

    DevExpress AI-powered Extensions operate within an AIExtensionsContainerDefault container. This container manages registered AI clients. Use the CreateDefaultAIExtensionContainer method to create a container for AI-powered extensions and register a chat client in a .NET console application.

    The following code snippets register an Azure OpenAI chat client:

    using Azure;
    using Azure.AI.OpenAI;
    using Microsoft.Extensions.AI;
    using DevExpress.AIIntegration;
    using DevExpress.AIIntegration.Extensions;
    
    SetEnvironmentVariables();
    
    // Register an Azure OpenAI client.
    AIExtensionsContainerDefault defaultAIExtensionsContainer = RegisterAzureOpenAIClient(
        Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"),
        Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
    );
    
    AIExtensionsContainerDefault RegisterAzureOpenAIClient(string azureOpenAIEndpoint, string azureOpenAIKey) {
        IChatClient client = new Azure.AI.OpenAI.AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
            new System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient("gpt-4o-mini").AsIChatClient();
    
        return AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(client);
    }
    
    void SetEnvironmentVariables() {
        Environment.SetEnvironmentVariable("AZURE_OPENAI_ENDPOINT", {SPECIFY_YOUR_AZURE_ENDPOINT});
        Environment.SetEnvironmentVariable("AZURE_OPENAI_APIKEY", {SPECIFY_YOU_AZURE_KEY});
    }
    
    using Azure;
    using Azure.AI.OpenAI;
    using Microsoft.Extensions.AI;
    using DevExpress.AIIntegration;
    using DevExpress.AIIntegration.Extensions;
    
    //...
    IChatClient client = new AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
        new System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient("gpt-4o-mini").AsIChatClient();
    
    AIExtensionsContainerDesktop.Default.RegisterChatClient(client);
    
    using DevExpress.AIIntegration;
    using Microsoft.Extensions.AI;
    using OpenAI;
    
    IChatClient client = new AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
        new System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient("gpt-4o-mini").AsIChatClient();
    
    builder.Services.AddSingleton(client);
    //or reference the Microsoft.Extensions.AI NuGet package and use
    //builder.Services.AddChatClient(config => config.Use(myChatClient));
    builder.Services.AddDevExpressAI();
    

    Read the following help topic for additional information: AI Integration.

    Tip

    Read the following help topics for information on how to register AI Clients in WinForms, WPF, and Blazor applications:

    The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CreateDefaultAIExtensionContainer(IChatClient, IAIExceptionHandler, IAIChatClientCustomizeMessageRequest) 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