Skip to content
Docs Try Aspire

AspireAzureAIInferenceExtensions Methods

Class Methods 4 members
Extension methods for adding Azure AI Inference services to an Aspire application.
AddAzureChatCompletionsClient(IHostApplicationBuilder, string, Action<ChatCompletionsClientSettings>, Action<IAzureClientBuilder<ChatCompletionsClient, AzureAIInferenceClientOptions>>) Section titled AddAzureChatCompletionsClient(IHostApplicationBuilder, string, Action<ChatCompletionsClientSettings>, Action<IAzureClientBuilder<ChatCompletionsClient, AzureAIInferenceClientOptions>>) extension AspireChatCompletionsClientBuilder
Adds a Inference.ChatCompletionsClient to the application and configures it with the specified settings.
public static class AspireAzureAIInferenceExtensions
{
public static AspireChatCompletionsClientBuilder AddAzureChatCompletionsClient(
this IHostApplicationBuilder builder,
string connectionName,
Action<ChatCompletionsClientSettings>? configureSettings = null,
Action<IAzureClientBuilder<ChatCompletionsClient, AzureAIInferenceClientOptions>>? configureClientBuilder = null)
{
// ...
}
}
builder IHostApplicationBuilder The Hosting.IHostApplicationBuilder to add the client to.
connectionName string The name of the client. This is used to retrieve the connection string from configuration.
configureSettings Action<ChatCompletionsClientSettings> optional An optional callback to configure the ChatCompletionsClientSettings.
configureClientBuilder Action<IAzureClientBuilder<ChatCompletionsClient, AzureAIInferenceClientOptions>> optional An optional callback to configure the Extensions.IAzureClientBuilder`2 for the client.
AspireChatCompletionsClientBuilder An AspireChatCompletionsClientBuilder that can be used to further configure the client.
InvalidOperationException Thrown when endpoint is missing from settings.

The client is registered as a singleton with a keyed service.

Configuration is loaded from the "Aspire:Azure:AI:Inference" section, and can be supplemented with a connection string named after the connectionName parameter.

AddChatClient(AspireChatCompletionsClientBuilder, string?) Section titled AddChatClient(AspireChatCompletionsClientBuilder, string?) extension ChatClientBuilder
Creates a AI.IChatClient from the Inference.ChatCompletionsClient registered in the service collection.
public static class AspireAzureAIInferenceExtensions
{
public static ChatClientBuilder AddChatClient(
this AspireChatCompletionsClientBuilder builder,
string? deploymentName = null)
{
// ...
}
}
deploymentName string? optional Optionally specifies which model deployment to use. If not specified, a value will be taken from the connection string.
AddKeyedAzureChatCompletionsClient(IHostApplicationBuilder, string, Action<ChatCompletionsClientSettings>, Action<IAzureClientBuilder<ChatCompletionsClient, AzureAIInferenceClientOptions>>) Section titled AddKeyedAzureChatCompletionsClient(IHostApplicationBuilder, string, Action<ChatCompletionsClientSettings>, Action<IAzureClientBuilder<ChatCompletionsClient, AzureAIInferenceClientOptions>>) extension AspireChatCompletionsClientBuilder
Adds a Inference.ChatCompletionsClient to the application and configures it with the specified settings.
public static class AspireAzureAIInferenceExtensions
{
public static AspireChatCompletionsClientBuilder AddKeyedAzureChatCompletionsClient(
this IHostApplicationBuilder builder,
string name,
Action<ChatCompletionsClientSettings>? configureSettings = null,
Action<IAzureClientBuilder<ChatCompletionsClient, AzureAIInferenceClientOptions>>? configureClientBuilder = null)
{
// ...
}
}
builder IHostApplicationBuilder The Hosting.IHostApplicationBuilder to add the client to.
name string The 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.
configureSettings Action<ChatCompletionsClientSettings> optional An optional callback to configure the ChatCompletionsClientSettings.
configureClientBuilder Action<IAzureClientBuilder<ChatCompletionsClient, AzureAIInferenceClientOptions>> optional An optional callback to configure the Extensions.IAzureClientBuilder`2 for the client.
AspireChatCompletionsClientBuilder An AspireChatCompletionsClientBuilder that can be used to further configure the client.
InvalidOperationException Thrown when endpoint is missing from settings.

The client is registered as a singleton with a keyed service.

Configuration is loaded from the "Aspire:Azure:AI:Inference" section, and can be supplemented with a connection string named after the name parameter.

AddKeyedChatClient(AspireChatCompletionsClientBuilder, string, string?) Section titled AddKeyedChatClient(AspireChatCompletionsClientBuilder, string, string?) extension ChatClientBuilder
Creates a AI.IChatClient from the Inference.ChatCompletionsClient registered in the service collection.
public static class AspireAzureAIInferenceExtensions
{
public static ChatClientBuilder AddKeyedChatClient(
this AspireChatCompletionsClientBuilder builder,
string serviceKey,
string? deploymentName = null)
{
// ...
}
}
serviceKey string The service key with which the AI.IChatClient will be registered.
deploymentName string? optional Optionally specifies which model deployment to use. If not specified, a value will be taken from the connection string.