Skip to content
DocsTry Aspire
DocsTry

AspireOpenAIExtensions Methods

ClassMethods2 members
Provides extension methods for registering OpenAIClient as a singleton in the services provided by the Hosting.IHostApplicationBuilder.
AddKeyedOpenAIClient(IHostApplicationBuilder, string, Action<OpenAISettings>, Action<OpenAIClientOptions>)Section titled AddKeyedOpenAIClient(IHostApplicationBuilder, string, Action<OpenAISettings>, Action<OpenAIClientOptions>)extensionAspireOpenAIClientBuilder
Registers OpenAIClient as a singleton for given name in the services provided by the builder.
public static class AspireOpenAIExtensions
{
public static AspireOpenAIClientBuilder AddKeyedOpenAIClient(
this IHostApplicationBuilder builder,
string name,
Action<OpenAISettings>? configureSettings = null,
Action<OpenAIClientOptions>? configureOptions = null)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
namestringThe name of the component, which is used as the ServiceDescriptor.ServiceKey of the service and also to retrieve the connection string from the ConnectionStrings configuration section.
configureSettingsAction<OpenAISettings>optionalAn optional method that can be used for customizing the OpenAISettings. It's invoked after the settings are read from the configuration.
configureOptionsAction<OpenAIClientOptions>optionalAn optional method that can be used for customizing the OpenAIClientOptions.
AspireOpenAIClientBuilderAn AspireOpenAIClientBuilder that can be used to register additional services.
Reads the configuration from "Aspire.OpenAI:{name}" section.
AddOpenAIClient(IHostApplicationBuilder, string, Action<OpenAISettings>, Action<OpenAIClientOptions>)Section titled AddOpenAIClient(IHostApplicationBuilder, string, Action<OpenAISettings>, Action<OpenAIClientOptions>)extensionAspireOpenAIClientBuilder
Registers OpenAIClient as a singleton in the services provided by the builder.
public static class AspireOpenAIExtensions
{
public static AspireOpenAIClientBuilder AddOpenAIClient(
this IHostApplicationBuilder builder,
string connectionName,
Action<OpenAISettings>? configureSettings = null,
Action<OpenAIClientOptions>? configureOptions = null)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
connectionNamestringA name used to retrieve the connection string from the ConnectionStrings configuration section.
configureSettingsAction<OpenAISettings>optionalAn optional method that can be used for customizing the OpenAISettings. It's invoked after the settings are read from the configuration.
configureOptionsAction<OpenAIClientOptions>optionalAn optional method that can be used for customizing the OpenAIClientOptions.
AspireOpenAIClientBuilderAn AspireOpenAIClientBuilder that can be used to register additional services.
Reads the configuration from "Aspire.OpenAI" section.