2025-03-12 10:31:01 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2025-03-12 17:05:27 +00:00
|
|
|
|
2025-04-24 11:50:14 +00:00
|
|
|
using AIStudio.Components;
|
2025-03-12 10:31:01 +00:00
|
|
|
using AIStudio.Settings;
|
2025-03-16 13:03:43 +00:00
|
|
|
using AIStudio.Tools.Services;
|
2025-03-12 10:31:01 +00:00
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
namespace AIStudio.Dialogs.Settings;
|
|
|
|
|
2025-04-24 11:50:14 +00:00
|
|
|
public abstract class SettingsDialogBase : MSGComponentBase
|
2025-03-12 10:31:01 +00:00
|
|
|
{
|
|
|
|
[CascadingParameter]
|
2025-03-12 18:12:56 +00:00
|
|
|
protected IMudDialogInstance MudDialog { get; set; } = null!;
|
2025-03-12 10:31:01 +00:00
|
|
|
|
|
|
|
[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();
|
2025-03-12 10:31:01 +00:00
|
|
|
|
|
|
|
#region Overrides of ComponentBase
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2025-03-16 20:05:33 +00:00
|
|
|
protected override async Task OnInitializedAsync()
|
2025-03-12 10:31:01 +00:00
|
|
|
{
|
2025-04-24 11:50:14 +00:00
|
|
|
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
|
2025-03-16 20:05:33 +00:00
|
|
|
|
2025-03-12 10:31:01 +00:00
|
|
|
this.UpdateProviders();
|
2025-03-16 13:03:43 +00:00
|
|
|
this.UpdateEmbeddingProviders();
|
2025-03-16 20:05:33 +00:00
|
|
|
await base.OnInitializedAsync();
|
2025-03-12 10:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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();
|
2025-03-12 10:31:01 +00:00
|
|
|
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-03-12 10:31:01 +00:00
|
|
|
}
|
2025-03-16 20:05:33 +00:00
|
|
|
|
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
|
2025-03-16 20:05:33 +00:00
|
|
|
{
|
|
|
|
switch (triggeredEvent)
|
|
|
|
{
|
|
|
|
case Event.CONFIGURATION_CHANGED:
|
|
|
|
this.StateHasChanged();
|
|
|
|
break;
|
|
|
|
}
|
2025-04-24 11:50:14 +00:00
|
|
|
|
2025-03-16 20:05:33 +00:00
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2025-03-12 10:31:01 +00:00
|
|
|
}
|