blazor-microsoft-dot-extensions-dot-dependencyinjection-dot-startupextensions-dot-adddevexpressai-x28-iservicecollection-action-aiwebsettings-x29.md
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.2.dll
NuGet Package : DevExpress.AIIntegration.Web
public static IServiceCollection AddDevExpressAI(
this IServiceCollection collection,
Action<AIWebSettings> configure = null
)
| Name | Type | Description |
|---|---|---|
| collection | IServiceCollection |
The application’s service collection.
|
| Name | Type | Default | Description |
|---|---|---|---|
| configure | Action<AIWebSettings> | null |
A delegate method that configures the OpenAI Assistant.
|
| Type | Description |
|---|---|
| IServiceCollection |
The modified application service collection.
|
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