Skip to main content
All docs
V24.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.v24.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 AzureOpenAIClient(
        new Uri(azureOpenAIEndpoint),
        new AzureKeyCredential(azureOpenAIKey))
            .AsChatClient("gpt-4o-mini");
    return AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(client);
}

void SetEnvironmentVariables() {
    Environment.SetEnvironmentVariable("AZURE_OPENAI_ENDPOINT", {SPECIFY_YOUR_AZURE_ENDPOINT});
    Environment.SetEnvironmentVariable("AZURE_OPENAI_APIKEY", {SPECIFY_YOU_AZURE_KEY});
}

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:

See Also