mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-06-23 07:36:26 +00:00
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
60 lines
2.5 KiB
C#
60 lines
2.5 KiB
C#
using AIStudio.Provider;
|
|
using AIStudio.Settings;
|
|
using AIStudio.Settings.DataModel;
|
|
|
|
namespace AIStudio.Chat;
|
|
|
|
public static class ChatThreadExtensions
|
|
{
|
|
/// <summary>
|
|
/// Checks if the specified provider is allowed for the chat thread.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// We don't check if the provider is allowed to use the data sources of the chat thread.
|
|
/// That kind of check is done in the RAG process itself.<br/><br/>
|
|
///
|
|
/// One thing which is not so obvious: after RAG was used on this thread, the entire chat
|
|
/// thread is kind of a data source by itself. Why? Because the augmentation data collected
|
|
/// from the data sources is stored in the chat thread. This means we must check if the
|
|
/// selected provider is allowed to use this thread's data.
|
|
/// </remarks>
|
|
/// <param name="chatThread">The chat thread to check.</param>
|
|
/// <param name="provider">The provider to check.</param>
|
|
/// <returns>True, when the provider is allowed for the chat thread. False, otherwise.</returns>
|
|
public static bool IsLLMProviderAllowed<T>(this ChatThread? chatThread, T provider)
|
|
{
|
|
// No chat thread available means we have a new chat. That's fine:
|
|
if (chatThread is null)
|
|
return true;
|
|
|
|
// The chat thread is available, but the data security is not specified.
|
|
// Means, we never used RAG or RAG was enabled, but no data sources were selected.
|
|
// That's fine as well:
|
|
if (chatThread.DataSecurity is DataSourceSecurity.NOT_SPECIFIED)
|
|
return true;
|
|
|
|
//
|
|
// Is the provider trusted for data-source security checks?
|
|
//
|
|
var settingsManager = Program.SERVICE_PROVIDER.GetRequiredService<SettingsManager>();
|
|
var isTrustedProvider = provider switch
|
|
{
|
|
IProvider p => p.IsTrustedForDataSourceSecurityChecks(settingsManager),
|
|
AIStudio.Settings.Provider p => p.IsTrustedForDataSourceSecurityChecks(settingsManager),
|
|
|
|
_ => false,
|
|
};
|
|
|
|
//
|
|
// Check the chat data security against the selected provider:
|
|
//
|
|
return isTrustedProvider switch
|
|
{
|
|
// The provider is trusted -- we can use any data source:
|
|
true => true,
|
|
|
|
// The provider is not trusted -- it depends on the data security of the chat thread:
|
|
false => chatThread.DataSecurity is not DataSourceSecurity.SELF_HOSTED,
|
|
};
|
|
}
|
|
} |