| | | 1 | | using Chronicis.Shared.DTOs; |
| | | 2 | | |
| | | 3 | | namespace Chronicis.Api.Services; |
| | | 4 | | |
| | | 5 | | public class AzureOpenAIHealthCheckService : HealthCheckServiceBase |
| | | 6 | | { |
| | | 7 | | private readonly IConfiguration _configuration; |
| | | 8 | | private readonly HttpClient _httpClient; |
| | | 9 | | |
| | | 10 | | public AzureOpenAIHealthCheckService( |
| | | 11 | | IConfiguration configuration, |
| | | 12 | | HttpClient httpClient, |
| | | 13 | | ILogger<AzureOpenAIHealthCheckService> logger) |
| | 0 | 14 | | : base(logger) |
| | | 15 | | { |
| | 0 | 16 | | _configuration = configuration; |
| | 0 | 17 | | _httpClient = httpClient; |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | protected override Task<(string Status, string? Message)> PerformHealthCheckAsync() |
| | | 21 | | { |
| | 0 | 22 | | var endpoint = _configuration["AzureOpenAI:Endpoint"]; |
| | 0 | 23 | | var apiKey = _configuration["AzureOpenAI:ApiKey"]; |
| | 0 | 24 | | var deploymentName = _configuration["AzureOpenAI:DeploymentName"]; |
| | | 25 | | |
| | 0 | 26 | | if (string.IsNullOrEmpty(endpoint) || string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(deploymentName)) |
| | | 27 | | { |
| | 0 | 28 | | return Task.FromResult<(string Status, string? Message)>((HealthStatus.Unhealthy, "Azure OpenAI configuratio |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | // For a lightweight check, we'll just verify the configuration is complete |
| | | 32 | | // A full check would require making an actual API call, but that might be expensive |
| | | 33 | | try |
| | | 34 | | { |
| | 0 | 35 | | var uri = new Uri(endpoint); |
| | 0 | 36 | | return Task.FromResult<(string Status, string? Message)>((HealthStatus.Healthy, "Azure OpenAI configuration |
| | | 37 | | } |
| | 0 | 38 | | catch (UriFormatException) |
| | | 39 | | { |
| | 0 | 40 | | return Task.FromResult<(string Status, string? Message)>((HealthStatus.Unhealthy, "Azure OpenAI endpoint URL |
| | | 41 | | } |
| | 0 | 42 | | } |
| | | 43 | | } |