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

@@ -144,19 +144,26 @@ public static class ConfigurationSelectDataFactory
yield return new(scheme.GetListDescription(), scheme);
}
public static IEnumerable<ConfigurationSelectData<ConfidenceLevel>> GetConfidenceLevelsData()
public static IEnumerable<ConfigurationSelectData<ConfidenceLevel>> GetConfidenceLevelsData(SettingsManager settingsManager, bool restrictToGlobalMinimum = false)
{
var minimumLevel = ConfidenceLevel.NONE;
if(restrictToGlobalMinimum && settingsManager.ConfigurationData.LLMProviders is { EnforceGlobalMinimumConfidence: true, GlobalMinimumConfidence: not ConfidenceLevel.NONE and not ConfidenceLevel.UNKNOWN })
minimumLevel = settingsManager.ConfigurationData.LLMProviders.GlobalMinimumConfidence;
foreach (var level in Enum.GetValues<ConfidenceLevel>())
{
if(level is ConfidenceLevel.NONE)
yield return new("No minimum confidence level chosen", level);
if(level < minimumLevel)
continue;
switch (level)
{
case ConfidenceLevel.NONE:
case ConfidenceLevel.UNKNOWN:
continue;
case ConfidenceLevel.NONE:
yield return new("No minimum confidence level chosen", level);
break;
default:
yield return new(level.GetName(), level);
break;
@@ -1,4 +1,5 @@
using AIStudio.Assistants.Agenda;
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
@@ -51,6 +52,11 @@ public sealed class DataAgenda
/// </summary>
public string PreselectedOtherLanguage { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// Preselect a agenda provider?
/// </summary>
@@ -1,4 +1,5 @@
using AIStudio.Assistants.Coding;
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
@@ -24,6 +25,11 @@ public sealed class DataCoding
/// </summary>
public string PreselectedOtherProgrammingLanguage { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// Which coding provider should be preselected?
/// </summary>
@@ -1,4 +1,5 @@
using AIStudio.Assistants.EMail;
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
@@ -23,16 +24,6 @@ public sealed class DataEMail
/// Preselect any writing style?
/// </summary>
public WritingStyles PreselectedWritingStyle { get; set; }
/// <summary>
/// Preselect a provider?
/// </summary>
public string PreselectedProvider { get; set; } = string.Empty;
/// <summary>
/// Preselect a profile?
/// </summary>
public string PreselectedProfile { get; set; } = string.Empty;
/// <summary>
/// Preselect a greeting phrase?
@@ -43,4 +34,19 @@ public sealed class DataEMail
/// Preselect the sender name for the closing salutation?
/// </summary>
public string SenderName { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// Preselect a provider?
/// </summary>
public string PreselectedProvider { get; set; } = string.Empty;
/// <summary>
/// Preselect a profile?
/// </summary>
public string PreselectedProfile { get; set; } = string.Empty;
}
@@ -1,3 +1,5 @@
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
public sealed class DataGrammarSpelling
@@ -17,6 +19,11 @@ public sealed class DataGrammarSpelling
/// </summary>
public string PreselectedOtherLanguage { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// Preselect a provider?
/// </summary>
@@ -1,4 +1,5 @@
using AIStudio.Assistants.IconFinder;
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
@@ -14,6 +15,11 @@ public sealed class DataIconFinder
/// </summary>
public IconSources PreselectedSource { get; set; }
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// The preselected icon provider.
/// </summary>
@@ -1,3 +1,5 @@
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
public class DataLegalCheck
@@ -22,6 +24,11 @@ public class DataLegalCheck
/// </summary>
public bool PreselectContentCleanerAgent { get; set; }
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// The preselected translator provider.
/// </summary>
@@ -1,3 +1,5 @@
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
public sealed class DataMyTasks
@@ -17,6 +19,11 @@ public sealed class DataMyTasks
/// </summary>
public string PreselectOtherLanguage { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// The preselected provider.
/// </summary>
@@ -1,4 +1,5 @@
using AIStudio.Assistants.RewriteImprove;
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
@@ -29,6 +30,11 @@ public sealed class DataRewriteImprove
/// </summary>
public SentenceStructure PreselectedSentenceStructure { get; set; }
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// Preselect a provider?
/// </summary>
@@ -1,3 +1,5 @@
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
public sealed class DataSynonyms
@@ -17,6 +19,11 @@ public sealed class DataSynonyms
/// </summary>
public string PreselectedOtherLanguage { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// Preselect a provider?
/// </summary>
@@ -1,4 +1,5 @@
using AIStudio.Assistants.TextSummarizer;
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
@@ -45,6 +46,11 @@ public sealed class DataTextSummarizer
/// </summary>
public string PreselectedExpertInField { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// Preselect a text summarizer provider?
/// </summary>
@@ -1,3 +1,5 @@
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
public sealed class DataTranslation
@@ -42,6 +44,11 @@ public sealed class DataTranslation
/// </summary>
public string PreselectOtherLanguage { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
/// <summary>
/// The preselected translator provider.
/// </summary>
@@ -112,51 +112,40 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
public void InjectSpellchecking(Dictionary<string, object?> attributes) => attributes["spellcheck"] = this.ConfigurationData.App.EnableSpellchecking ? "true" : "false";
public ConfidenceLevel GetMinimumConfidenceLevel(Tools.Components component)
{
var minimumLevel = ConfidenceLevel.NONE;
var enforceGlobalMinimumConfidence = this.ConfigurationData.LLMProviders is { EnforceGlobalMinimumConfidence: true, GlobalMinimumConfidence: not ConfidenceLevel.NONE and not ConfidenceLevel.UNKNOWN };
if (enforceGlobalMinimumConfidence)
minimumLevel = this.ConfigurationData.LLMProviders.GlobalMinimumConfidence;
var componentMinimumLevel = component.MinimumConfidence(this);
if (componentMinimumLevel > minimumLevel)
minimumLevel = componentMinimumLevel;
return minimumLevel;
}
public Provider GetPreselectedProvider(Tools.Components component)
{
var minimumLevel = this.ConfigurationData.LLMProviders.EnforceGlobalMinimumConfidence ? this.ConfigurationData.LLMProviders.GlobalMinimumConfidence : ConfidenceLevel.NONE;
var minimumLevel = this.GetMinimumConfidenceLevel(component);
// When there is only one provider, and it has a confidence level that is high enough, we return it:
if (this.ConfigurationData.Providers.Count == 1 && this.ConfigurationData.Providers[0].UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
return this.ConfigurationData.Providers[0];
var preselection = component switch
{
Tools.Components.CHAT => this.ConfigurationData.Chat.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.Chat.PreselectedProvider) : default,
Tools.Components.GRAMMAR_SPELLING_ASSISTANT => this.ConfigurationData.GrammarSpelling.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.GrammarSpelling.PreselectedProvider) : default,
Tools.Components.ICON_FINDER_ASSISTANT => this.ConfigurationData.IconFinder.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.IconFinder.PreselectedProvider) : default,
Tools.Components.REWRITE_ASSISTANT => this.ConfigurationData.RewriteImprove.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.RewriteImprove.PreselectedProvider) : default,
Tools.Components.TRANSLATION_ASSISTANT => this.ConfigurationData.Translation.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.Translation.PreselectedProvider) : default,
Tools.Components.AGENDA_ASSISTANT => this.ConfigurationData.Agenda.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.Agenda.PreselectedProvider) : default,
Tools.Components.CODING_ASSISTANT => this.ConfigurationData.Coding.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.Coding.PreselectedProvider) : default,
Tools.Components.TEXT_SUMMARIZER_ASSISTANT => this.ConfigurationData.TextSummarizer.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.TextSummarizer.PreselectedProvider) : default,
Tools.Components.EMAIL_ASSISTANT => this.ConfigurationData.EMail.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.EMail.PreselectedProvider) : default,
Tools.Components.LEGAL_CHECK_ASSISTANT => this.ConfigurationData.LegalCheck.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.LegalCheck.PreselectedProvider) : default,
Tools.Components.SYNONYMS_ASSISTANT => this.ConfigurationData.Synonyms.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.Synonyms.PreselectedProvider) : default,
Tools.Components.MY_TASKS_ASSISTANT => this.ConfigurationData.MyTasks.PreselectOptions ? this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.MyTasks.PreselectedProvider) : default,
_ => default,
};
if(preselection != default && preselection.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
return preselection;
// When there is a component-preselected provider, and it has a confidence level that is high enough, we return it:
var preselectedProvider = component.PreselectedProvider(this);
if(preselectedProvider != default && preselectedProvider.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
return preselectedProvider;
// When there is an app-wide preselected provider, and it has a confidence level that is high enough, we return it:
return this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.App.PreselectedProvider && x.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel);
}
public Profile GetPreselectedProfile(Tools.Components component)
{
var preselection = component switch
{
Tools.Components.CHAT => this.ConfigurationData.Chat.PreselectOptions ? this.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == this.ConfigurationData.Chat.PreselectedProfile) : default,
Tools.Components.AGENDA_ASSISTANT => this.ConfigurationData.Agenda.PreselectOptions ? this.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == this.ConfigurationData.Agenda.PreselectedProfile) : default,
Tools.Components.CODING_ASSISTANT => this.ConfigurationData.Coding.PreselectOptions ? this.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == this.ConfigurationData.Coding.PreselectedProfile) : default,
Tools.Components.EMAIL_ASSISTANT => this.ConfigurationData.EMail.PreselectOptions ? this.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == this.ConfigurationData.EMail.PreselectedProfile) : default,
Tools.Components.LEGAL_CHECK_ASSISTANT => this.ConfigurationData.LegalCheck.PreselectOptions ? this.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == this.ConfigurationData.LegalCheck.PreselectedProfile) : default,
Tools.Components.MY_TASKS_ASSISTANT => this.ConfigurationData.MyTasks.PreselectOptions ? this.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == this.ConfigurationData.MyTasks.PreselectedProfile) : default,
_ => default,
};
var preselection = component.PreselectedProfile(this);
if (preselection != default)
return preselection;