2025-02-23 14:05:29 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
2024-09-13 21:29:19 +00:00
|
|
|
using AIStudio.Provider;
|
2026-07-04 16:28:52 +00:00
|
|
|
using AIStudio.Settings;
|
2024-08-05 19:12:52 +00:00
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
2024-08-21 06:30:01 +00:00
|
|
|
namespace AIStudio.Components;
|
2024-08-05 19:12:52 +00:00
|
|
|
|
2025-04-27 07:06:05 +00:00
|
|
|
public partial class ProviderSelection : MSGComponentBase
|
2024-08-05 19:12:52 +00:00
|
|
|
{
|
2024-09-14 17:20:33 +00:00
|
|
|
[CascadingParameter]
|
2026-01-29 06:26:36 +00:00
|
|
|
public Tools.Components? Component { get; set; }
|
2025-08-26 08:59:56 +00:00
|
|
|
|
2024-08-05 19:12:52 +00:00
|
|
|
[Parameter]
|
2025-08-26 08:59:56 +00:00
|
|
|
public AIStudio.Settings.Provider ProviderSettings { get; set; } = AIStudio.Settings.Provider.NONE;
|
2024-08-05 19:12:52 +00:00
|
|
|
|
|
|
|
|
[Parameter]
|
2025-01-05 14:11:15 +00:00
|
|
|
public EventCallback<AIStudio.Settings.Provider> ProviderSettingsChanged { get; set; }
|
2024-08-05 19:12:52 +00:00
|
|
|
|
|
|
|
|
[Parameter]
|
2025-01-05 14:11:15 +00:00
|
|
|
public Func<AIStudio.Settings.Provider, string?> ValidateProvider { get; set; } = _ => null;
|
2026-02-01 13:50:19 +00:00
|
|
|
|
2026-07-03 13:02:20 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether provider selection is disabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Disabled { get; set; }
|
|
|
|
|
|
2026-02-01 13:50:19 +00:00
|
|
|
[Parameter]
|
|
|
|
|
public ConfidenceLevel ExplicitMinimumConfidence { get; set; } = ConfidenceLevel.UNKNOWN;
|
2024-08-05 19:12:52 +00:00
|
|
|
|
2026-01-29 06:26:36 +00:00
|
|
|
[Inject]
|
|
|
|
|
private ILogger<ProviderSelection> Logger { get; init; } = null!;
|
2026-06-21 13:59:23 +00:00
|
|
|
|
|
|
|
|
#region Overrides of ComponentBase
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
|
|
|
|
|
await base.OnInitializedAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2026-01-29 06:26:36 +00:00
|
|
|
|
2025-01-05 14:11:15 +00:00
|
|
|
private async Task SelectionChanged(AIStudio.Settings.Provider provider)
|
2024-08-05 19:12:52 +00:00
|
|
|
{
|
|
|
|
|
this.ProviderSettings = provider;
|
|
|
|
|
await this.ProviderSettingsChanged.InvokeAsync(provider);
|
|
|
|
|
}
|
2026-07-04 16:28:52 +00:00
|
|
|
|
|
|
|
|
private IEnumerable<ProviderSelectionItem> GetAvailableProviderSelectionItems()
|
|
|
|
|
{
|
|
|
|
|
foreach (var provider in this.GetAvailableProviders())
|
|
|
|
|
yield return new(provider, this.GetCapabilityIcons(provider));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IReadOnlyList<CapabilityIcon> GetCapabilityIcons(AIStudio.Settings.Provider provider)
|
|
|
|
|
{
|
|
|
|
|
var capabilities = provider.GetModelCapabilities();
|
|
|
|
|
List<CapabilityIcon> capabilityIcons = [];
|
|
|
|
|
|
|
|
|
|
if (capabilities.Contains(Capability.AUDIO_INPUT))
|
|
|
|
|
capabilityIcons.Add(new(Icons.Material.Filled.GraphicEq, this.T("Audio input possible")));
|
|
|
|
|
|
|
|
|
|
if (capabilities.Contains(Capability.SINGLE_IMAGE_INPUT) || capabilities.Contains(Capability.MULTIPLE_IMAGE_INPUT))
|
|
|
|
|
capabilityIcons.Add(new(Icons.Material.Filled.Image, this.T("Image input possible")));
|
|
|
|
|
|
|
|
|
|
if (capabilities.Contains(Capability.SPEECH_INPUT))
|
|
|
|
|
capabilityIcons.Add(new(Icons.Material.Filled.Mic, this.T("Speech input possible")));
|
|
|
|
|
|
|
|
|
|
var reasoningIndicatorState = provider.GetReasoningIndicatorState();
|
|
|
|
|
if (reasoningIndicatorState is not ReasoningIndicatorState.NONE)
|
|
|
|
|
capabilityIcons.Add(new(Icons.Material.Filled.Psychology, this.GetReasoningTooltip(reasoningIndicatorState)));
|
|
|
|
|
|
|
|
|
|
return capabilityIcons;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetReasoningTooltip(ReasoningIndicatorState reasoningIndicatorState) => reasoningIndicatorState switch
|
|
|
|
|
{
|
|
|
|
|
ReasoningIndicatorState.DEFAULT_ON => this.T("Uses reasoning (thinking) by default"),
|
|
|
|
|
ReasoningIndicatorState.CONFIGURED => this.T("Uses reasoning (thinking) configured by settings"),
|
|
|
|
|
_ => this.T("Uses reasoning (thinking)"),
|
|
|
|
|
};
|
2024-09-13 21:29:19 +00:00
|
|
|
|
2025-02-23 14:05:29 +00:00
|
|
|
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
2025-01-05 14:11:15 +00:00
|
|
|
private IEnumerable<AIStudio.Settings.Provider> GetAvailableProviders()
|
2024-09-13 21:29:19 +00:00
|
|
|
{
|
2026-01-29 06:26:36 +00:00
|
|
|
switch (this.Component)
|
|
|
|
|
{
|
|
|
|
|
case null:
|
|
|
|
|
this.Logger.LogError("Component is null! Cannot filter providers based on component settings. Missed CascadingParameter?");
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
case Tools.Components.NONE:
|
|
|
|
|
this.Logger.LogError("Component is NONE! Cannot filter providers based on component settings. Used wrong component?");
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
case { } component:
|
2026-02-01 13:50:19 +00:00
|
|
|
|
|
|
|
|
// Get the minimum confidence level for this component, and/or the global minimum if enforced:
|
2026-01-29 06:26:36 +00:00
|
|
|
var minimumLevel = this.SettingsManager.GetMinimumConfidenceLevel(component);
|
2026-02-01 13:50:19 +00:00
|
|
|
|
|
|
|
|
// Override with the explicit minimum level if set and higher:
|
|
|
|
|
if (this.ExplicitMinimumConfidence is not ConfidenceLevel.UNKNOWN && this.ExplicitMinimumConfidence > minimumLevel)
|
|
|
|
|
minimumLevel = this.ExplicitMinimumConfidence;
|
|
|
|
|
|
|
|
|
|
// Filter providers based on the minimum confidence level:
|
2026-01-29 06:26:36 +00:00
|
|
|
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
|
|
|
|
|
if (provider.UsedLLMProvider != LLMProviders.NONE)
|
|
|
|
|
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
|
|
|
|
|
yield return provider;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-09-13 21:29:19 +00:00
|
|
|
}
|
2026-06-21 13:59:23 +00:00
|
|
|
|
|
|
|
|
#region Overrides of MSGComponentBase
|
|
|
|
|
|
|
|
|
|
protected override Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
|
|
|
|
|
{
|
|
|
|
|
if (triggeredEvent is Event.CONFIGURATION_CHANGED or Event.PLUGINS_RELOADED)
|
|
|
|
|
this.StateHasChanged();
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2026-07-04 16:28:52 +00:00
|
|
|
|
|
|
|
|
private readonly record struct CapabilityIcon(string Icon, string Tooltip);
|
|
|
|
|
|
|
|
|
|
private readonly record struct ProviderSelectionItem(AIStudio.Settings.Provider Provider, IReadOnlyList<CapabilityIcon> CapabilityIcons);
|
2024-08-05 19:12:52 +00:00
|
|
|
}
|