first version of the import function

This commit is contained in:
Peer Hogeterp committed 2026-09-24 17:20:54 +02:00
1 parent fda42ac24b
commit 0e63f93696
39 files changed
+1535 -46

No files matched your search

@@ -3,8 +3,11 @@ using AIStudio.Provider;
using AIStudio.Provider.HuggingFace;
using AIStudio.Settings;
using AIStudio.Tools.Services;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Validation;
using Lua;
using Microsoft.AspNetCore.Components;
using Host = AIStudio.Provider.SelfHosted.Host;
@@ -13,6 +16,9 @@ namespace AIStudio.Dialogs;
public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
{
[Parameter]
public LuaTable? ImportedConfiguration { get; set; }
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!;
@@ -107,6 +113,7 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
private string dataAPIKey = string.Empty;
private bool dataHadStoredAPIKeyOnLoad;
private string dataAPIKeyStorageIssue = string.Empty;
private string importCredentialIssue = string.Empty;
private string dataEditingPreviousInstanceName = string.Empty;
private string dataLoadingModelsIssue = string.Empty;
@@ -153,6 +160,33 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
HFInferenceProvider = this.HFInferenceProviderId,
};
}
private Task ImportConfiguration(LuaTable table)
{
ConfigurationImportFields.ValidateExportId(table);
var modelTable = ConfigurationImportFields.Table(table, "Model");
var model = new Model(ConfigurationImportFields.String(modelTable, "Id"), ConfigurationImportFields.String(modelTable, "DisplayName"));
var name = ConfigurationImportFields.String(table, "Name");
var provider = ConfigurationImportFields.Enum<LLMProviders>(table, "UsedLLMProvider");
var host = ConfigurationImportFields.Enum<Host>(table, "Host");
var hostname = ConfigurationImportFields.String(table, "Hostname");
var hfProvider = table.TryGetValue("HFInferenceProvider", out _)
? ConfigurationImportFields.Enum<HFInferenceProvider>(table, "HFInferenceProvider") : HFInferenceProvider.NONE;
var credential = ConfigurationImportFields.Credential(table, "APIKey", out var credentialIssue);
this.DataName = name;
this.DataLLMProvider = provider;
this.DataHost = host;
this.DataHostname = hostname;
this.HFInferenceProviderId = hfProvider;
this.DataModel = model;
this.dataAPIKey = credential;
this.importCredentialIssue = credentialIssue;
if (this.availableModels.All(candidate => candidate.Id != model.Id))
this.availableModels.Add(model);
this.form.ResetValidation();
return Task.CompletedTask;
}
#region Overrides of ComponentBase
@@ -205,6 +239,15 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
// We don't want to show validation errors when the user opens the dialog.
if(!this.IsEditing && firstRender)
this.form.ResetValidation();
if (firstRender && this.ImportedConfiguration is not null)
{
if (!this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("TRANSCRIPTION_PROVIDERS"))
this.MudDialog.Cancel();
else
await this.ImportConfiguration(this.ImportedConfiguration);
this.StateHasChanged();
}
await base.OnAfterRenderAsync(firstRender);
}
@@ -225,6 +268,9 @@ public partial class TranscriptionProviderDialog : MSGComponentBase, ISecretId
private async Task Store()
{
if (this.ImportedConfiguration is not null && !this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("TRANSCRIPTION_PROVIDERS"))
return;
await this.form.Validate();
this.dataAPIKeyStorageIssue = string.Empty;