@page "/settings" @using Intendant.Shared.Services @inject IOpenAiSettingsService SettingsService @inject IOpenAiResponsesService ResponsesService Paramètres

Paramètres OpenAI

@if (!string.IsNullOrWhiteSpace(message)) { } @if (!string.IsNullOrWhiteSpace(error)) { } @if (!string.IsNullOrWhiteSpace(testResult)) { } @code { private string apiKey = string.Empty; private string endpoint = string.Empty; private string model = string.Empty; private string message = string.Empty; private string error = string.Empty; private string testResult = string.Empty; private bool isBusy; protected override async Task OnInitializedAsync() { OpenAiResponsesOptions settings = await SettingsService.GetAsync(); apiKey = settings.ApiKey; endpoint = settings.Endpoint; model = settings.Model; } private async Task SaveAsync() { isBusy = true; error = string.Empty; testResult = string.Empty; try { await SettingsService.SaveAsync(new OpenAiResponsesOptions { ApiKey = apiKey, Endpoint = endpoint, Model = model, }); message = "Paramètres enregistrés."; } catch (Exception ex) { message = string.Empty; error = ex.Message; } finally { isBusy = false; } } private async Task TestAsync() { isBusy = true; error = string.Empty; message = string.Empty; testResult = string.Empty; try { await SettingsService.SaveAsync(new OpenAiResponsesOptions { ApiKey = apiKey, Endpoint = endpoint, Model = model, }); string response = await ResponsesService.GenerateTextAsync("Réponds uniquement par: OK"); testResult = response; } catch (Exception ex) { error = ex.Message; } finally { isBusy = false; } } }