Ajoutez des fichiers projet.
This commit is contained in:
1 parent
2f1b2a0dcc
commit
99b860c967
68 files changed
+1974
No files matched your search
@@ -0,0 +1,118 @@
|
||||
@page "/settings"
|
||||
@using Intendant.Shared.Services
|
||||
@inject IOpenAiSettingsService SettingsService
|
||||
@inject IOpenAiResponsesService ResponsesService
|
||||
|
||||
<PageTitle>Paramètres</PageTitle>
|
||||
|
||||
<h1>Paramètres OpenAI</h1>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="openai-api-key">Clé API (optionnelle)</label>
|
||||
<input id="openai-api-key" class="form-control" @bind="apiKey" />
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="openai-endpoint">Endpoint</label>
|
||||
<input id="openai-endpoint" class="form-control" @bind="endpoint" placeholder="https://api.openai.com/v1" />
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="openai-model">Modèle</label>
|
||||
<input id="openai-model" class="form-control" @bind="model" placeholder="gpt-5-mini" />
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-primary" @onclick="SaveAsync" disabled="@isBusy">Enregistrer</button>
|
||||
<button type="button" class="btn btn-outline-secondary" @onclick="TestAsync" disabled="@isBusy">Tester</button>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
<div class="alert alert-success mt-3" role="alert">@message</div>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
<div class="alert alert-danger mt-3" role="alert">@error</div>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrWhiteSpace(testResult))
|
||||
{
|
||||
<div class="alert alert-info mt-3" role="alert">@testResult</div>
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user