using System.Net.Http.Json; namespace FictionArchive.Service.TranslationService.Services.TranslationEngines.NanoGpt; public class NanoGptApiClient { private readonly HttpClient _httpClient; private readonly ILogger _logger; public NanoGptApiClient(HttpClient httpClient, ILogger logger) { _httpClient = httpClient; _logger = logger; } public async Task CompleteAsync( string model, IReadOnlyList messages, double temperature, CancellationToken ct = default) { var request = new NanoGptChatRequest(model, messages, temperature); using var response = await _httpClient.PostAsJsonAsync("v1/chat/completions", request, ct); response.EnsureSuccessStatusCode(); var body = await response.Content.ReadFromJsonAsync(ct); if (body is null) { throw new InvalidOperationException("NanoGPT returned an empty response body."); } return body; } }