Added a way for organizations to prohibit providers (#1105)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-10-22 18:57:12 +02:00
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));
}