using System.Net.Http.Json; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace GymLogAI.AI; public sealed class OpenRouterEmbeddingClient( HttpClient httpClient, IOptions options, ILogger logger) { private readonly OpenRouterOptions _options = options.Value; public async Task GenerateAsync(string input, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(_options.ApiKey)) { logger.LogInformation("OpenRouter API key is not configured. Returning stubbed embedding."); return null; } using var request = new HttpRequestMessage(HttpMethod.Post, "embeddings") { Content = JsonContent.Create(new { model = _options.EmbeddingModel, input }) }; request.Headers.Authorization = new("Bearer", _options.ApiKey); var response = await httpClient.SendAsync(request, cancellationToken); response.EnsureSuccessStatusCode(); return null; } }