/
afanasevn
/
PdfEncoder
Обзор
Документация
Войти
/
afanasevn
/
PdfEncoder
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/PdfEncoder.Infrastructure/Health/LlmHealthCheck.cs
46 строк
2 KB
IBS\NAfanasev
Add project files.
01 июл 2026, 14:54
01 июл 2026, 14:54
8414644
Код
Авторство
О чём код?
using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Options; using PdfEncoder.Application.Options; namespace PdfEncoder.Infrastructure.Health; /// <summary> /// Проверка доступности LLM gateway (или пропуск при SkipLlm). /// </summary> public sealed class LlmHealthCheck( IOptions<LlmModelOptions> options, IHttpClientFactory httpClientFactory) : IHealthCheck { /// <inheritdoc /> public async Task<HealthCheckResult> CheckHealthAsync( HealthCheckContext context, CancellationToken ct = default) { var llmOptions = options.Value; if (llmOptions.SkipLlm) { return HealthCheckResult.Healthy("LLM checks skipped."); } if (string.IsNullOrWhiteSpace(llmOptions.BaseUrl)) { return HealthCheckResult.Unhealthy("Llm__BaseUrl is not configured."); } try { var client = httpClientFactory.CreateClient("LlmHealth"); using var request = new HttpRequestMessage(HttpMethod.Head, llmOptions.BaseUrl.TrimEnd('/')); using var response = await client.SendAsync(request, ct); return response.IsSuccessStatusCode ? HealthCheckResult.Healthy("LLM gateway responded.") : HealthCheckResult.Degraded($"LLM gateway returned {(int)response.StatusCode}."); } catch (Exception ex) { return HealthCheckResult.Degraded("LLM gateway is unreachable.", ex); } } }