mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 15:27:21 +00:00
Added a way for organizations to prohibit providers (#1105)
This commit is contained in:
1 parent
052868b24e
commit
7ba5f01388
38 files changed
+1488
-629
No files matched your search
@@ -7,12 +7,30 @@ namespace AIStudio.Tools.Services;
|
||||
|
||||
internal static class DataSourceEmbeddingProviders
|
||||
{
|
||||
/// <summary>
|
||||
/// Finds the embedding provider of a data source, when AI Studio may use it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A provider the organization prohibited counts as missing: nothing may be embedded with it,
|
||||
/// neither the documents of the data source nor a query against its index.
|
||||
/// </remarks>
|
||||
public static bool TryResolve(SettingsManager settingsManager, IDataSourceBase dataSource, [NotNullWhen(true)] out EmbeddingProvider? embeddingProvider)
|
||||
{
|
||||
embeddingProvider = settingsManager.ConfigurationData.EmbeddingProviders.FirstOrDefault(provider =>
|
||||
dataSource is IIndexedDataSource indexedDataSource &&
|
||||
provider.Id.Equals(indexedDataSource.EmbeddingId, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
return embeddingProvider != default && embeddingProvider.UsedLLMProvider is not LLMProviders.NONE;
|
||||
embeddingProvider = Find(settingsManager, dataSource);
|
||||
return embeddingProvider is { UsedLLMProvider: not LLMProviders.NONE } && !settingsManager.IsProviderProhibited(embeddingProvider.UsedLLMProvider);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the organization prohibited the embedding provider of a data source.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// TryResolve fails for such a provider as well, but without the reason. The status of a data
|
||||
/// source needs the reason to tell the user what to change.
|
||||
/// </remarks>
|
||||
public static bool IsProhibited(SettingsManager settingsManager, IDataSourceBase dataSource)
|
||||
=> Find(settingsManager, dataSource) is { } embeddingProvider && settingsManager.IsProviderProhibited(embeddingProvider.UsedLLMProvider);
|
||||
|
||||
private static EmbeddingProvider? Find(SettingsManager settingsManager, IDataSourceBase dataSource) => settingsManager.ConfigurationData.EmbeddingProviders.FirstOrDefault(provider =>
|
||||
dataSource is IIndexedDataSource indexedDataSource &&
|
||||
provider.Id.Equals(indexedDataSource.EmbeddingId, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
@@ -801,7 +801,9 @@ public sealed partial class DataSourceEmbeddingService(SettingsManager settingsM
|
||||
if (!this.TryResolveEmbeddingProvider(dataSource, out var embeddingProvider))
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
this.UpsertStatus(this.GetFallbackStatus(dataSource, TB("The selected embedding provider is not available. Please check it in the settings.")));
|
||||
this.UpsertStatus(this.GetFallbackStatus(dataSource, DataSourceEmbeddingProviders.IsProhibited(settingsManager, dataSource)
|
||||
? TB("The use of the embedding provider of this data source has been prohibited by your organization. Please select a different embedding provider in the settings of the data source.")
|
||||
: TB("The selected embedding provider is not available. Please check it in the settings.")));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -754,10 +754,11 @@ public sealed class MediaTranscriptionService(
|
||||
|
||||
/// <summary>Resolves the configured provider after confidence validation.</summary>
|
||||
/// <remarks>
|
||||
/// Checks the global minimum confidence only. A caller with rules of its own, such as the
|
||||
/// confidence level of a data source, checks the provider against them as well.
|
||||
/// Checks the global minimum confidence and whether the organization prohibited the provider. A
|
||||
/// caller with rules of its own, such as the confidence level of a data source, checks the
|
||||
/// provider against them as well.
|
||||
/// </remarks>
|
||||
/// <returns>The configured provider, or null when none is configured or it falls short of the global minimum.</returns>
|
||||
/// <returns>The configured provider, or null when none is configured, it falls short of the global minimum, or it is prohibited.</returns>
|
||||
public TranscriptionProvider? GetUsableProvider()
|
||||
{
|
||||
var providerId = settingsManager.ConfigurationData.App.UseTranscriptionProvider;
|
||||
@@ -769,7 +770,7 @@ public sealed class MediaTranscriptionService(
|
||||
return null;
|
||||
|
||||
var minimumLevel = settingsManager.GetMinimumConfidenceLevel(Components.NONE);
|
||||
return providerSettings.UsedLLMProvider.GetConfidence(settingsManager).Level >= minimumLevel
|
||||
return settingsManager.IsProviderUsable(providerSettings.UsedLLMProvider, minimumLevel)
|
||||
? providerSettings
|
||||
: null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user