Added options to enforce minimum confidence levels for each assistant (#147)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2024-09-14 19:20:33 +02:00
1 parent 4175387a93
commit 0ad7b8d4dd
36 files changed
+321 -144

No files matched your search

@@ -0,0 +1,2 @@
@using AIStudio.Settings
<ConfigurationSelect Disabled="@this.Disabled" OptionDescription="Select a minimum confidence level" SelectedValue="@this.FilteredSelectedValue" Data="@ConfigurationSelectDataFactory.GetConfidenceLevelsData(this.SettingsManager, this.RestrictToGlobalMinimumConfidence)" SelectionUpdate="@this.SelectionUpdate" OptionHelp="Choose the minimum confidence level that all LLM providers must meet. This way, you can ensure that only trustworthy providers are used. You cannot use any provider that falls below this level."/>
@@ -0,0 +1,51 @@
using AIStudio.Provider;
using AIStudio.Settings;
using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class ConfigurationMinConfidenceSelection : ComponentBase
{
/// <summary>
/// The selected value.
/// </summary>
[Parameter]
public Func<ConfidenceLevel> SelectedValue { get; set; } = () => default!;
/// <summary>
/// An action that is called when the selection changes.
/// </summary>
[Parameter]
public Action<ConfidenceLevel> SelectionUpdate { get; set; } = _ => { };
/// <summary>
/// Is the selection component disabled?
/// </summary>
[Parameter]
public Func<bool> Disabled { get; set; } = () => false;
/// <summary>
/// Boolean value indicating whether the selection is restricted to a global minimum confidence level.
/// </summary>
[Parameter]
public bool RestrictToGlobalMinimumConfidence { get; set; }
[Inject]
private SettingsManager SettingsManager { get; init; } = null!;
private ConfidenceLevel FilteredSelectedValue()
{
if (this.SelectedValue() is ConfidenceLevel.NONE)
return ConfidenceLevel.NONE;
if(this.RestrictToGlobalMinimumConfidence && this.SettingsManager.ConfigurationData.LLMProviders.EnforceGlobalMinimumConfidence)
{
var minimumLevel = this.SettingsManager.ConfigurationData.LLMProviders.GlobalMinimumConfidence;
if(this.SelectedValue() < minimumLevel)
return minimumLevel;
}
return this.SelectedValue();
}
}
@@ -24,6 +24,9 @@ public partial class ConfigurationProviderSelection : ComponentBase, IMessageBus
[Parameter]
public Func<string> HelpText { get; set; } = () => "Select a provider that is preselected.";
[Parameter]
public Tools.Components Component { get; set; } = Tools.Components.NONE;
[Inject]
private SettingsManager SettingsManager { get; init; } = null!;
@@ -46,20 +49,12 @@ public partial class ConfigurationProviderSelection : ComponentBase, IMessageBus
private IEnumerable<ConfigurationSelectData<string>> FilteredData()
{
if (this.SettingsManager.ConfigurationData.LLMProviders is { EnforceGlobalMinimumConfidence: true, GlobalMinimumConfidence: not ConfidenceLevel.NONE and not ConfidenceLevel.UNKNOWN })
var minimumLevel = this.SettingsManager.GetMinimumConfidenceLevel(this.Component);
foreach (var providerId in this.Data)
{
var minimumLevel = this.SettingsManager.ConfigurationData.LLMProviders.GlobalMinimumConfidence;
foreach (var providerId in this.Data)
{
var provider = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == providerId.Value);
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
yield return providerId;
}
}
else
{
foreach (var provider in this.Data)
yield return provider;
var provider = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == providerId.Value);
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
yield return providerId;
}
}
@@ -1,3 +1,4 @@
using AIStudio.Assistants;
using AIStudio.Provider;
using AIStudio.Settings;
@@ -7,6 +8,9 @@ namespace AIStudio.Components;
public partial class ProviderSelection : ComponentBase
{
[CascadingParameter]
public AssistantBase? AssistantBase { get; set; }
[Parameter]
public Settings.Provider ProviderSettings { get; set; }
@@ -27,17 +31,9 @@ public partial class ProviderSelection : ComponentBase
private IEnumerable<Settings.Provider> GetAvailableProviders()
{
if (this.SettingsManager.ConfigurationData.LLMProviders is { EnforceGlobalMinimumConfidence: true, GlobalMinimumConfidence: not ConfidenceLevel.NONE and not ConfidenceLevel.UNKNOWN })
{
var minimumLevel = this.SettingsManager.ConfigurationData.LLMProviders.GlobalMinimumConfidence;
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
yield return provider;
}
else
{
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
var minimumLevel = this.SettingsManager.GetMinimumConfidenceLevel(this.AssistantBase?.Component ?? Tools.Components.NONE);
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
yield return provider;
}
}
}