mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 15:13:49 +00:00
Added optional enforcement for a min. confidence level (#145)
This commit is contained in:
1 parent
1cac1a7913
commit
4175387a93
15 files changed
+242
-16
No files matched your search
@@ -4,6 +4,7 @@ using AIStudio.Assistants.IconFinder;
|
||||
using AIStudio.Assistants.RewriteImprove;
|
||||
using AIStudio.Assistants.TextSummarizer;
|
||||
using AIStudio.Assistants.EMail;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings.DataModel;
|
||||
|
||||
using WritingStylesRewrite = AIStudio.Assistants.RewriteImprove.WritingStyles;
|
||||
@@ -142,4 +143,24 @@ public static class ConfigurationSelectDataFactory
|
||||
foreach (var scheme in Enum.GetValues<ConfidenceSchemes>())
|
||||
yield return new(scheme.GetListDescription(), scheme);
|
||||
}
|
||||
|
||||
public static IEnumerable<ConfigurationSelectData<ConfidenceLevel>> GetConfidenceLevelsData()
|
||||
{
|
||||
foreach (var level in Enum.GetValues<ConfidenceLevel>())
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public sealed class Data
|
||||
/// The version of the settings file. Allows us to upgrade the settings
|
||||
/// when a new version is available.
|
||||
/// </summary>
|
||||
public Version Version { get; init; } = Version.V4;
|
||||
public Version Version { get; init; } = Version.V5;
|
||||
|
||||
/// <summary>
|
||||
/// List of configured providers.
|
||||
|
||||
@@ -4,6 +4,16 @@ namespace AIStudio.Settings.DataModel;
|
||||
|
||||
public sealed class DataLLMProviders
|
||||
{
|
||||
/// <summary>
|
||||
/// Should we enforce a global minimum confidence level?
|
||||
/// </summary>
|
||||
public bool EnforceGlobalMinimumConfidence { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The global minimum confidence level to enforce.
|
||||
/// </summary>
|
||||
public ConfidenceLevel GlobalMinimumConfidence { get; set; } = ConfidenceLevel.NONE;
|
||||
|
||||
/// <summary>
|
||||
/// Should we show the provider confidence level?
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
namespace AIStudio.Settings.DataModel.PreviousModels;
|
||||
|
||||
public sealed class DataV4
|
||||
{
|
||||
/// <summary>
|
||||
/// The version of the settings file. Allows us to upgrade the settings
|
||||
/// when a new version is available.
|
||||
/// </summary>
|
||||
public Version Version { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// List of configured providers.
|
||||
/// </summary>
|
||||
public List<Provider> Providers { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Settings concerning the LLM providers.
|
||||
/// </summary>
|
||||
public DataLLMProviders LLMProviders { get; init; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// List of configured profiles.
|
||||
/// </summary>
|
||||
public List<Profile> Profiles { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The next provider number to use.
|
||||
/// </summary>
|
||||
public uint NextProviderNum { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The next profile number to use.
|
||||
/// </summary>
|
||||
public uint NextProfileNum { get; set; } = 1;
|
||||
|
||||
public DataApp App { get; init; } = new();
|
||||
|
||||
public DataChat Chat { get; init; } = new();
|
||||
|
||||
public DataWorkspace Workspace { get; init; } = new();
|
||||
|
||||
public DataIconFinder IconFinder { get; init; } = new();
|
||||
|
||||
public DataTranslation Translation { get; init; } = new();
|
||||
|
||||
public DataCoding Coding { get; init; } = new();
|
||||
|
||||
public DataTextSummarizer TextSummarizer { get; init; } = new();
|
||||
|
||||
public DataTextContentCleaner TextContentCleaner { get; init; } = new();
|
||||
|
||||
public DataAgenda Agenda { get; init; } = new();
|
||||
|
||||
public DataGrammarSpelling GrammarSpelling { get; init; } = new();
|
||||
|
||||
public DataRewriteImprove RewriteImprove { get; init; } = new();
|
||||
|
||||
public DataEMail EMail { get; set; } = new();
|
||||
|
||||
public DataLegalCheck LegalCheck { get; set; } = new();
|
||||
|
||||
public DataSynonyms Synonyms { get; set; } = new();
|
||||
|
||||
public DataMyTasks MyTasks { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
using Host = AIStudio.Provider.SelfHosted.Host;
|
||||
|
||||
namespace AIStudio.Settings.DataModel.PreviousModels;
|
||||
|
||||
public readonly record struct Provider(
|
||||
uint Num,
|
||||
string Id,
|
||||
string InstanceName,
|
||||
LLMProviders UsedProvider,
|
||||
Model Model,
|
||||
bool IsSelfHosted = false,
|
||||
string Hostname = "http://localhost:1234",
|
||||
Host Host = Host.NONE);
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace AIStudio.Settings.DataModel.PreviousModels;
|
||||
|
||||
public static class ProviderV4Extensions
|
||||
{
|
||||
public static List<Settings.Provider> MigrateFromV4ToV5(this IEnumerable<Provider> providers)
|
||||
{
|
||||
return providers.Select(provider => provider.MigrateFromV4ToV5()).ToList();
|
||||
}
|
||||
|
||||
public static Settings.Provider MigrateFromV4ToV5(this Provider provider) => new()
|
||||
{
|
||||
Num = provider.Num,
|
||||
Id = provider.Id,
|
||||
InstanceName = provider.InstanceName,
|
||||
UsedLLMProvider = provider.UsedProvider,
|
||||
Model = provider.Model,
|
||||
IsSelfHosted = provider.IsSelfHosted,
|
||||
Hostname = provider.Hostname,
|
||||
Host = provider.Host,
|
||||
};
|
||||
}
|
||||
@@ -114,7 +114,9 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
||||
|
||||
public Provider GetPreselectedProvider(Tools.Components component)
|
||||
{
|
||||
if(this.ConfigurationData.Providers.Count == 1)
|
||||
var minimumLevel = this.ConfigurationData.LLMProviders.EnforceGlobalMinimumConfidence ? this.ConfigurationData.LLMProviders.GlobalMinimumConfidence : ConfidenceLevel.NONE;
|
||||
|
||||
if (this.ConfigurationData.Providers.Count == 1 && this.ConfigurationData.Providers[0].UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
|
||||
return this.ConfigurationData.Providers[0];
|
||||
|
||||
var preselection = component switch
|
||||
@@ -135,10 +137,10 @@ public sealed class SettingsManager(ILogger<SettingsManager> logger)
|
||||
_ => default,
|
||||
};
|
||||
|
||||
if (preselection != default)
|
||||
if(preselection != default && preselection.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
|
||||
return preselection;
|
||||
|
||||
return this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.App.PreselectedProvider);
|
||||
return this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.App.PreselectedProvider && x.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel);
|
||||
}
|
||||
|
||||
public Profile GetPreselectedProfile(Tools.Components component)
|
||||
|
||||
@@ -23,7 +23,8 @@ public static class SettingsMigrations
|
||||
|
||||
configV1 = MigrateV1ToV2(logger, configV1);
|
||||
configV1 = MigrateV2ToV3(logger, configV1);
|
||||
return MigrateV3ToV4(logger, configV1);
|
||||
var configV14 = MigrateV3ToV4(logger, configV1);
|
||||
return MigrateV4ToV5(logger, configV14);
|
||||
|
||||
case Version.V2:
|
||||
var configV2 = JsonSerializer.Deserialize<DataV1V3>(configData, jsonOptions);
|
||||
@@ -34,7 +35,8 @@ public static class SettingsMigrations
|
||||
}
|
||||
|
||||
configV2 = MigrateV2ToV3(logger, configV2);
|
||||
return MigrateV3ToV4(logger, configV2);
|
||||
var configV24 = MigrateV3ToV4(logger, configV2);
|
||||
return MigrateV4ToV5(logger, configV24);
|
||||
|
||||
case Version.V3:
|
||||
var configV3 = JsonSerializer.Deserialize<DataV1V3>(configData, jsonOptions);
|
||||
@@ -44,18 +46,29 @@ public static class SettingsMigrations
|
||||
return new();
|
||||
}
|
||||
|
||||
return MigrateV3ToV4(logger, configV3);
|
||||
|
||||
default:
|
||||
logger.LogInformation("No configuration migration is needed.");
|
||||
var configV4 = JsonSerializer.Deserialize<Data>(configData, jsonOptions);
|
||||
var configV34 = MigrateV3ToV4(logger, configV3);
|
||||
return MigrateV4ToV5(logger, configV34);
|
||||
|
||||
case Version.V4:
|
||||
var configV4 = JsonSerializer.Deserialize<DataV4>(configData, jsonOptions);
|
||||
if (configV4 is null)
|
||||
{
|
||||
logger.LogError("Failed to parse the v4 configuration. Using default values.");
|
||||
return new();
|
||||
}
|
||||
|
||||
return configV4;
|
||||
return MigrateV4ToV5(logger, configV4);
|
||||
|
||||
default:
|
||||
logger.LogInformation("No configuration migration is needed.");
|
||||
var configV5 = JsonSerializer.Deserialize<Data>(configData, jsonOptions);
|
||||
if (configV5 is null)
|
||||
{
|
||||
logger.LogError("Failed to parse the v4 configuration. Using default values.");
|
||||
return new();
|
||||
}
|
||||
|
||||
return configV5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +123,7 @@ public static class SettingsMigrations
|
||||
};
|
||||
}
|
||||
|
||||
private static Data MigrateV3ToV4(ILogger<SettingsManager> logger, DataV1V3 previousConfig)
|
||||
private static DataV4 MigrateV3ToV4(ILogger<SettingsManager> logger, DataV1V3 previousConfig)
|
||||
{
|
||||
//
|
||||
// Summary:
|
||||
@@ -194,4 +207,38 @@ public static class SettingsMigrations
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private static Data MigrateV4ToV5(ILogger<SettingsManager> logger, DataV4 previousConfig)
|
||||
{
|
||||
//
|
||||
// Summary:
|
||||
// We renamed the LLM provider enum.
|
||||
//
|
||||
|
||||
logger.LogInformation("Migrating from v4 to v5...");
|
||||
return new()
|
||||
{
|
||||
Version = Version.V5,
|
||||
Providers = previousConfig.Providers.MigrateFromV4ToV5(),
|
||||
LLMProviders = previousConfig.LLMProviders,
|
||||
Profiles = previousConfig.Profiles,
|
||||
NextProviderNum = previousConfig.NextProviderNum,
|
||||
NextProfileNum = previousConfig.NextProfileNum,
|
||||
App = previousConfig.App,
|
||||
Chat = previousConfig.Chat,
|
||||
Workspace = previousConfig.Workspace,
|
||||
IconFinder = previousConfig.IconFinder,
|
||||
Translation = previousConfig.Translation,
|
||||
Coding = previousConfig.Coding,
|
||||
TextSummarizer = previousConfig.TextSummarizer,
|
||||
TextContentCleaner = previousConfig.TextContentCleaner,
|
||||
Agenda = previousConfig.Agenda,
|
||||
GrammarSpelling = previousConfig.GrammarSpelling,
|
||||
RewriteImprove = previousConfig.RewriteImprove,
|
||||
EMail = previousConfig.EMail,
|
||||
LegalCheck = previousConfig.LegalCheck,
|
||||
Synonyms = previousConfig.Synonyms,
|
||||
MyTasks = previousConfig.MyTasks,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,5 @@ public enum Version
|
||||
V2,
|
||||
V3,
|
||||
V4,
|
||||
V5,
|
||||
}
|
||||
Reference in new issue
Block a user