Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ protected override void BindSettingsToConfiguration(ChatCompletionsClientSetting
=> configuration.Bind(settings);

protected override IHealthCheck CreateHealthCheck(ChatCompletionsClient client, ChatCompletionsClientSettings settings)
=> throw new NotImplementedException();
=> new AzureAIInferenceChatCompletionsHealthCheck(client);

protected override bool GetHealthCheckEnabled(ChatCompletionsClientSettings settings)
=> false;
=> !settings.DisableHealthChecks;

protected override bool GetMetricsEnabled(ChatCompletionsClientSettings settings)
=> !settings.DisableMetrics;
Expand Down Expand Up @@ -439,10 +439,10 @@ protected override void BindSettingsToConfiguration(ChatCompletionsClientSetting
=> configuration.Bind(settings);

protected override IHealthCheck CreateHealthCheck(EmbeddingsClient client, ChatCompletionsClientSettings settings)
=> throw new NotImplementedException();
=> new AzureAIInferenceEmbeddingsHealthCheck(client);

protected override bool GetHealthCheckEnabled(ChatCompletionsClientSettings settings)
=> false;
=> !settings.DisableHealthChecks;

protected override bool GetMetricsEnabled(ChatCompletionsClientSettings settings)
=> !settings.DisableMetrics;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Azure.AI.Inference;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace Aspire.Azure.AI.Inference;

internal sealed class AzureAIInferenceChatCompletionsHealthCheck : IHealthCheck
{
private readonly ChatCompletionsClient _client;

public AzureAIInferenceChatCompletionsHealthCheck(ChatCompletionsClient client)
=> _client = client;

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
await _client.GetModelInfoAsync(cancellationToken).ConfigureAwait(false);
return HealthCheckResult.Healthy();
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Azure.AI.Inference;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace Aspire.Azure.AI.Inference;

internal sealed class AzureAIInferenceEmbeddingsHealthCheck : IHealthCheck
{
private readonly EmbeddingsClient _client;

public AzureAIInferenceEmbeddingsHealthCheck(EmbeddingsClient client)
=> _client = client;

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
await _client.GetModelInfoAsync(cancellationToken).ConfigureAwait(false);
return HealthCheckResult.Healthy();
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public sealed class ChatCompletionsClientSettings : IConnectionStringSettings
/// </summary>
public string? Key { get; set; }

/// <summary>
/// Gets or sets a boolean value that indicates whether the health check is disabled or not.
/// </summary>
/// <value>
/// The default value is <see langword="false"/>.
/// </value>
public bool DisableHealthChecks { get; set; }

/// <summary>
/// Gets or sets a boolean value that indicates whether the OpenTelemetry metrics are enabled or not.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
"type": "string",
"description": "Gets or sets the name of the AI model deployment to use for chat completions."
},
"DisableHealthChecks": {
"type": "boolean",
"description": "Gets or sets a boolean value that indicates whether the health check is disabled or not.",
"default": false
},
"DisableMetrics": {
"type": "boolean",
"description": "Gets or sets a boolean value that indicates whether the OpenTelemetry metrics are enabled or not.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public sealed partial class ChatCompletionsClientSettings

public string? DeploymentName { get { throw null; } set { } }

public bool DisableHealthChecks { get { throw null; } set { } }

public bool DisableMetrics { get { throw null; } set { } }

public bool DisableTracing { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ protected override void BindSettingsToConfiguration(AzureOpenAISettings settings

protected override IHealthCheck CreateHealthCheck(AzureOpenAIClient client, AzureOpenAISettings settings)
{
throw new NotImplementedException();
// Azure OpenAI does not expose a lightweight read-only health check endpoint.
// GetOpenAIModelClient() explicitly throws NotSupportedException in AzureOpenAIClient,
// and all other sub-clients require a deployment name and initiate inference operations.
// Health checks remain disabled until a suitable API is available in the Azure.AI.OpenAI SDK.
throw new NotSupportedException("Health checks are not supported for AzureOpenAIClient.");
}

protected override bool GetHealthCheckEnabled(AzureOpenAISettings settings)
Expand Down
2 changes: 1 addition & 1 deletion tests/Aspire.Azure.AI.Inference.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void ConfigureCredentials(ChatCompletionsClientSettings settings)
}

protected override void SetHealthCheck(ChatCompletionsClientSettings options, bool enabled)
=> throw new NotImplementedException();
=> options.DisableHealthChecks = !enabled;

protected override void SetMetrics(ChatCompletionsClientSettings options, bool enabled)
=> options.DisableMetrics = !enabled;
Expand Down
Loading