AI-Studio/app/MindWork AI Studio/Dialogs/Settings/SettingsDialogBase.cs

71 lines
2.1 KiB
C#
Raw Normal View History

using System.Diagnostics.CodeAnalysis;
2025-03-12 17:05:27 +00:00
2025-04-24 11:50:14 +00:00
using AIStudio.Components;
using AIStudio.Settings;
2025-03-16 13:03:43 +00:00
using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Dialogs.Settings;
2025-04-24 11:50:14 +00:00
public abstract class SettingsDialogBase : MSGComponentBase
{
[CascadingParameter]
2025-03-12 18:12:56 +00:00
protected IMudDialogInstance MudDialog { get; set; } = null!;
[Inject]
protected IDialogService DialogService { get; init; } = null!;
2025-03-16 13:03:43 +00:00
[Inject]
protected RustService RustService { get; init; } = null!;
protected readonly List<ConfigurationSelectData<string>> availableLLMProviders = new();
protected readonly List<ConfigurationSelectData<string>> availableEmbeddingProviders = new();
#region Overrides of ComponentBase
/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
2025-04-24 11:50:14 +00:00
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
this.UpdateProviders();
2025-03-16 13:03:43 +00:00
this.UpdateEmbeddingProviders();
await base.OnInitializedAsync();
}
#endregion
protected void Close() => this.MudDialog.Cancel();
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
private void UpdateProviders()
{
2025-03-16 13:03:43 +00:00
this.availableLLMProviders.Clear();
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
2025-03-16 13:03:43 +00:00
this.availableLLMProviders.Add(new (provider.InstanceName, provider.Id));
}
private void UpdateEmbeddingProviders()
{
this.availableEmbeddingProviders.Clear();
foreach (var provider in this.SettingsManager.ConfigurationData.EmbeddingProviders)
this.availableEmbeddingProviders.Add(new (provider.Name, provider.Id));
}
2025-04-24 11:50:14 +00:00
#region Overrides of MSGComponentBase
protected override Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
{
switch (triggeredEvent)
{
case Event.CONFIGURATION_CHANGED:
this.StateHasChanged();
break;
}
2025-04-24 11:50:14 +00:00
return Task.CompletedTask;
}
#endregion
}