mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 22:18:00 +00:00
refactored confidence levels and ensured checks work
This commit is contained in:
1 parent
786b106096
commit
88999d985c
44 files changed
+324
-335
No files matched your search
@@ -304,7 +304,7 @@ public static class ConfigurationSelectDataFactory
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<ConfigurationSelectData<ConfidenceLevel>> GetDataSourceComplianceLevelsData()
|
||||
public static IEnumerable<ConfigurationSelectData<ConfidenceLevel>> GetDataSourceConfidenceLevelsData()
|
||||
{
|
||||
foreach (var level in Enum.GetValues<ConfidenceLevel>())
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
using AIStudio.Assistants.ERI;
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Tools.ERIClient;
|
||||
using AIStudio.Tools.ERIClient.DataModel;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
@@ -59,9 +58,6 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
/// <inheritdoc />
|
||||
public DataSourceSecurity SecurityPolicy { get; init; } = DataSourceSecurity.NOT_SPECIFIED;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ConfidenceLevel ComplianceLevel { get; init; } = ConfidenceLevel.UNKNOWN;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsEnterpriseConfiguration { get; init; }
|
||||
|
||||
@@ -211,16 +207,6 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
return false;
|
||||
}
|
||||
|
||||
var complianceLevel = ConfidenceLevel.UNKNOWN;
|
||||
if (table.TryGetValue("ComplianceLevel", out var complianceLevelValue) &&
|
||||
(!complianceLevelValue.TryRead<string>(out var complianceLevelText) ||
|
||||
!Enum.TryParse(complianceLevelText, true, out complianceLevel) ||
|
||||
complianceLevel is ConfidenceLevel.NONE))
|
||||
{
|
||||
LOGGER.LogWarning($"The configured data source {idx} contains an invalid compliance level. Falling back to UNKNOWN. (Plugin ID: {configPluginId})");
|
||||
complianceLevel = ConfidenceLevel.UNKNOWN;
|
||||
}
|
||||
|
||||
if (!table.TryGetValue("SelectedRetrievalId", out var selectedRetrievalIdValue) || !selectedRetrievalIdValue.TryRead<string>(out var selectedRetrievalId) || string.IsNullOrWhiteSpace(selectedRetrievalId))
|
||||
{
|
||||
LOGGER.LogWarning($"The configured data source {idx} must specify a selected retrieval ID. (Plugin ID: {configPluginId})");
|
||||
@@ -278,7 +264,6 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
Username = username,
|
||||
UsernamePasswordMode = usernamePasswordMode,
|
||||
SecurityPolicy = securityPolicy,
|
||||
ComplianceLevel = complianceLevel,
|
||||
Version = ERIVersion.V1,
|
||||
SelectedRetrievalId = selectedRetrievalId,
|
||||
MaxMatches = (ushort)maxMatches,
|
||||
@@ -339,7 +324,6 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
|
||||
{{usernameLine}}
|
||||
{{secretLine}}
|
||||
["SecurityPolicy"] = "{{this.SecurityPolicy}}",
|
||||
["ComplianceLevel"] = "{{this.ComplianceLevel}}",
|
||||
["SelectedRetrievalId"] = "{{LuaTools.EscapeLuaString(this.SelectedRetrievalId)}}",
|
||||
["MaxMatches"] = {{this.MaxMatches}},
|
||||
}
|
||||
|
||||
@@ -42,10 +42,7 @@ public readonly record struct DataSourceLocalDirectory : IInternalDataSource
|
||||
public int ChunkOverlapTokenLength { get; init; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DataSourceSecurity SecurityPolicy { get; init; } = DataSourceSecurity.ALLOW_ANY;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ConfidenceLevel ComplianceLevel { get; init; } = ConfidenceLevel.UNKNOWN;
|
||||
public ConfidenceLevel ConfidenceLevel { get; init; } = ConfidenceLevel.UNKNOWN;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsEnterpriseConfiguration { get; init; }
|
||||
|
||||
@@ -42,10 +42,7 @@ public readonly record struct DataSourceLocalFile : IInternalDataSource
|
||||
public int ChunkOverlapTokenLength { get; init; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DataSourceSecurity SecurityPolicy { get; init; } = DataSourceSecurity.ALLOW_ANY;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ConfidenceLevel ComplianceLevel { get; init; } = ConfidenceLevel.UNKNOWN;
|
||||
public ConfidenceLevel ConfidenceLevel { get; init; } = ConfidenceLevel.UNKNOWN;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsEnterpriseConfiguration { get; init; }
|
||||
|
||||
@@ -61,30 +61,21 @@ public static class DataSourceSecurityTrustExtensions
|
||||
return provider.Provider.GetConfidence(settingsManager).Level;
|
||||
}
|
||||
|
||||
public static bool AllowsDataSourceAccess(this Provider provider, SettingsManager settingsManager, DataSourceSecurity dataSourceSecurity, ConfidenceLevel dataSourceComplianceLevel)
|
||||
public static bool AllowsDataSourceAccess(this Provider provider, SettingsManager settingsManager, DataSourceSecurity dataSourceSecurity, ConfidenceLevel requiredConfidenceLevel)
|
||||
{
|
||||
return provider.AllowsDataSourceSecurity(dataSourceSecurity, settingsManager)
|
||||
&& provider.GetConfidenceLevel(settingsManager).AllowsDataSourceComplianceLevel(dataSourceComplianceLevel);
|
||||
&& provider.GetConfidenceLevel(settingsManager).AllowsDataSourceConfidenceLevel(requiredConfidenceLevel);
|
||||
}
|
||||
|
||||
public static bool AllowsDataSourceAccess(this EmbeddingProvider provider, SettingsManager settingsManager, DataSourceSecurity dataSourceSecurity, ConfidenceLevel dataSourceComplianceLevel)
|
||||
public static bool AllowsDataSourceAccess(this IProvider provider, SettingsManager settingsManager, DataSourceSecurity dataSourceSecurity, ConfidenceLevel requiredConfidenceLevel)
|
||||
{
|
||||
return provider.AllowsDataSourceSecurity(dataSourceSecurity, settingsManager)
|
||||
&& provider.GetConfidenceLevel(settingsManager).AllowsDataSourceComplianceLevel(dataSourceComplianceLevel);
|
||||
}
|
||||
|
||||
public static bool AllowsDataSourceAccess(this IProvider provider, SettingsManager settingsManager, DataSourceSecurity dataSourceSecurity, ConfidenceLevel dataSourceComplianceLevel)
|
||||
{
|
||||
return provider.AllowsDataSourceSecurity(dataSourceSecurity, settingsManager)
|
||||
&& provider.GetConfidenceLevel(settingsManager).AllowsDataSourceComplianceLevel(dataSourceComplianceLevel);
|
||||
&& provider.GetConfidenceLevel(settingsManager).AllowsDataSourceConfidenceLevel(requiredConfidenceLevel);
|
||||
}
|
||||
|
||||
public static bool AllowsDataSourceSecurity(this Provider provider, DataSourceSecurity dataSourceSecurity, SettingsManager settingsManager)
|
||||
=> provider.IsTrustedForDataSourceSecurityChecks(settingsManager).AllowsDataSourceSecurity(dataSourceSecurity);
|
||||
|
||||
public static bool AllowsDataSourceSecurity(this EmbeddingProvider provider, DataSourceSecurity dataSourceSecurity, SettingsManager settingsManager)
|
||||
=> provider.IsTrustedForDataSourceSecurityChecks(settingsManager).AllowsDataSourceSecurity(dataSourceSecurity);
|
||||
|
||||
public static bool AllowsDataSourceSecurity(this IProvider provider, DataSourceSecurity dataSourceSecurity, SettingsManager settingsManager)
|
||||
=> provider.IsTrustedForDataSourceSecurityChecks(settingsManager).AllowsDataSourceSecurity(dataSourceSecurity);
|
||||
|
||||
@@ -95,28 +86,28 @@ public static class DataSourceSecurityTrustExtensions
|
||||
_ => false,
|
||||
};
|
||||
|
||||
public static bool AllowsDataSourceComplianceLevel(this ConfidenceLevel providerConfidenceLevel, ConfidenceLevel dataSourceComplianceLevel)
|
||||
public static bool AllowsDataSourceConfidenceLevel(this ConfidenceLevel providerConfidenceLevel, ConfidenceLevel requiredConfidenceLevel)
|
||||
{
|
||||
if (dataSourceComplianceLevel is ConfidenceLevel.NONE)
|
||||
if (requiredConfidenceLevel is ConfidenceLevel.NONE)
|
||||
return true;
|
||||
|
||||
return providerConfidenceLevel >= dataSourceComplianceLevel;
|
||||
return providerConfidenceLevel >= requiredConfidenceLevel;
|
||||
}
|
||||
|
||||
public static ConfidenceLevel GetRequiredComplianceLevel(this IEnumerable<IDataSource> dataSources)
|
||||
public static ConfidenceLevel GetRequiredConfidenceLevel(this IEnumerable<IDataSource> dataSources)
|
||||
{
|
||||
var requiredComplianceLevel = ConfidenceLevel.NONE;
|
||||
foreach (var dataSource in dataSources)
|
||||
if (dataSource.ComplianceLevel > requiredComplianceLevel)
|
||||
requiredComplianceLevel = dataSource.ComplianceLevel;
|
||||
var requiredConfidenceLevel = ConfidenceLevel.NONE;
|
||||
foreach (var dataSource in dataSources.OfType<IInternalDataSource>())
|
||||
if (dataSource.ConfidenceLevel > requiredConfidenceLevel)
|
||||
requiredConfidenceLevel = dataSource.ConfidenceLevel;
|
||||
|
||||
return requiredComplianceLevel;
|
||||
return requiredConfidenceLevel;
|
||||
}
|
||||
|
||||
public static DataSourceSecurity GetRequiredSecurityPolicy(this IEnumerable<IDataSource> dataSources)
|
||||
{
|
||||
var requiredSecurityPolicy = DataSourceSecurity.ALLOW_ANY;
|
||||
foreach (var dataSource in dataSources)
|
||||
foreach (var dataSource in dataSources.OfType<IExternalDataSource>())
|
||||
{
|
||||
if (dataSource.SecurityPolicy is DataSourceSecurity.NOT_SPECIFIED)
|
||||
return DataSourceSecurity.NOT_SPECIFIED;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.RAG;
|
||||
@@ -22,16 +21,6 @@ public interface IDataSource : IConfigurationObject
|
||||
/// </summary>
|
||||
public DataSourceType Type { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Which data security policy is applied to this data source?
|
||||
/// </summary>
|
||||
public DataSourceSecurity SecurityPolicy { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Which compliance level is assigned to this data source?
|
||||
/// </summary>
|
||||
public ConfidenceLevel ComplianceLevel { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of matches to return when retrieving data from the ERI server.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using AIStudio.Settings.DataModel;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public interface IExternalDataSource : IDataSource, ISecretId
|
||||
{
|
||||
/// <summary>
|
||||
/// Which data security policy is applied to this external data source?
|
||||
/// </summary>
|
||||
public DataSourceSecurity SecurityPolicy { get; init; }
|
||||
|
||||
#region Implementation of ISecretId
|
||||
|
||||
[JsonIgnore]
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public interface IInternalDataSource : IDataSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Which provider confidence level is required by this internal data source?
|
||||
/// </summary>
|
||||
public ConfidenceLevel ConfidenceLevel { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The unique identifier of the embedding method used by this internal data source.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user