Skip to main content
All docs
V25.1
  • StartupExtensions.AddDevExpressAI(IServiceCollection, Action<AIWebSettings>) Method

    Adds DevExpress AI-related services to the application service collection and allows you to configure OpenAI Assistant.

    Namespace: Microsoft.Extensions.DependencyInjection

    Assembly: DevExpress.AIIntegration.Web.v25.1.dll

    NuGet Package: DevExpress.AIIntegration.Web

    Declaration

    public static IServiceCollection AddDevExpressAI(
        this IServiceCollection collection,
        Action<AIWebSettings> configure = null
    )

    Parameters

    Name Type Description
    collection IServiceCollection

    The application’s service collection.

    Optional Parameters

    Name Type Default Description
    configure Action<AIWebSettings> null

    A delegate method that configures the OpenAI Assistant.

    Returns

    Type Description
    IServiceCollection

    The modified application service collection.

    Remarks

    The AddDevExpressAI method registers AI services and enables DevExpress AI-powered extensions in your application. You can supply this method with a parameter to additionally register the OpenAI Assistant.

    using Microsoft.Extensions.AI;
    ...
    string azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
    string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
    string deploymentName = "gpt4o";
    ...
    var azureClient = new AzureOpenAIClient(
        new Uri(azureOpenAIEndpoint),
        new ApiKeyCredential(azureOpenAIKey));
    
    builder.Services.AddDevExpressBlazor();
    builder.Services.AddChatClient(cfg => cfg.Use(azureClient.AsChatClient(deploymentName)));
    
    // Enables DevExpress AI-powered extensions
    builder.Services.AddDevExpressAI();
    // Or
    // Enables DevExpress AI-powered extensions and registers the OpenAI Assistant
    builder.Services.AddDevExpressAI((config) => {
        config.RegisterOpenAIAssistants(azureClient, "gpt4o"); 
    });
    
    See Also