mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-20 20:12:57 +00:00
Merge 8d45411e54
into be11efed67
This commit is contained in:
commit
9ef0585e81
@ -54,7 +54,7 @@ public abstract class AgentBase(ILogger<AgentBase> logger, SettingsManager setti
|
|||||||
|
|
||||||
#region Implementation of IAgent
|
#region Implementation of IAgent
|
||||||
|
|
||||||
public abstract AIStudio.Settings.Provider? ProviderSettings { get; set; }
|
public abstract AIStudio.Settings.Provider ProviderSettings { get; set; }
|
||||||
|
|
||||||
public abstract Task<ChatThread> ProcessContext(ChatThread chatThread, IDictionary<string, string> additionalData);
|
public abstract Task<ChatThread> ProcessContext(ChatThread chatThread, IDictionary<string, string> additionalData);
|
||||||
|
|
||||||
@ -103,10 +103,9 @@ public abstract class AgentBase(ILogger<AgentBase> logger, SettingsManager setti
|
|||||||
|
|
||||||
protected async Task AddAIResponseAsync(ChatThread thread, IContent lastUserPrompt, DateTimeOffset time)
|
protected async Task AddAIResponseAsync(ChatThread thread, IContent lastUserPrompt, DateTimeOffset time)
|
||||||
{
|
{
|
||||||
if(this.ProviderSettings is null)
|
if(this.ProviderSettings == Settings.Provider.NONE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var providerSettings = this.ProviderSettings.Value;
|
|
||||||
var aiText = new ContentText
|
var aiText = new ContentText
|
||||||
{
|
{
|
||||||
// We have to wait for the remote
|
// We have to wait for the remote
|
||||||
@ -127,6 +126,6 @@ public abstract class AgentBase(ILogger<AgentBase> logger, SettingsManager setti
|
|||||||
// Use the selected provider to get the AI response.
|
// Use the selected provider to get the AI response.
|
||||||
// By awaiting this line, we wait for the entire
|
// By awaiting this line, we wait for the entire
|
||||||
// content to be streamed.
|
// content to be streamed.
|
||||||
await aiText.CreateFromProviderAsync(providerSettings.CreateProvider(this.Logger), providerSettings.Model, lastUserPrompt, thread);
|
await aiText.CreateFromProviderAsync(this.ProviderSettings.CreateProvider(this.Logger), this.ProviderSettings.Model, lastUserPrompt, thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -86,7 +86,7 @@ public sealed class AgentDataSourceSelection (ILogger<AgentDataSourceSelection>
|
|||||||
""";
|
""";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Settings.Provider? ProviderSettings { get; set; }
|
public override Settings.Provider ProviderSettings { get; set; } = Settings.Provider.NONE;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The data source selection agent does not work with context. Use
|
/// The data source selection agent does not work with context. Use
|
||||||
@ -141,6 +141,11 @@ public sealed class AgentDataSourceSelection (ILogger<AgentDataSourceSelection>
|
|||||||
|
|
||||||
// We start with the provider currently selected by the user:
|
// We start with the provider currently selected by the user:
|
||||||
var agentProvider = this.SettingsManager.GetPreselectedProvider(Tools.Components.AGENT_DATA_SOURCE_SELECTION, provider.Id, true);
|
var agentProvider = this.SettingsManager.GetPreselectedProvider(Tools.Components.AGENT_DATA_SOURCE_SELECTION, provider.Id, true);
|
||||||
|
if (agentProvider == Settings.Provider.NONE)
|
||||||
|
{
|
||||||
|
logger.LogWarning("No provider is selected for the agent. The agent cannot select data sources.");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
// Assign the provider settings to the agent:
|
// Assign the provider settings to the agent:
|
||||||
logger.LogInformation($"The agent for the data source selection uses the provider '{agentProvider.InstanceName}' ({agentProvider.UsedLLMProvider.ToName()}, confidence={agentProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level.GetName()}).");
|
logger.LogInformation($"The agent for the data source selection uses the provider '{agentProvider.InstanceName}' ({agentProvider.UsedLLMProvider.ToName()}, confidence={agentProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level.GetName()}).");
|
||||||
|
@ -71,7 +71,7 @@ public sealed class AgentRetrievalContextValidation (ILogger<AgentRetrievalConte
|
|||||||
""";
|
""";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Settings.Provider? ProviderSettings { get; set; }
|
public override Settings.Provider ProviderSettings { get; set; } = Settings.Provider.NONE;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The retrieval context validation agent does not work with context. Use
|
/// The retrieval context validation agent does not work with context. Use
|
||||||
@ -133,6 +133,11 @@ public sealed class AgentRetrievalContextValidation (ILogger<AgentRetrievalConte
|
|||||||
{
|
{
|
||||||
// We start with the provider currently selected by the user:
|
// We start with the provider currently selected by the user:
|
||||||
var agentProvider = this.SettingsManager.GetPreselectedProvider(Tools.Components.AGENT_RETRIEVAL_CONTEXT_VALIDATION, provider.Id, true);
|
var agentProvider = this.SettingsManager.GetPreselectedProvider(Tools.Components.AGENT_RETRIEVAL_CONTEXT_VALIDATION, provider.Id, true);
|
||||||
|
if (agentProvider == Settings.Provider.NONE)
|
||||||
|
{
|
||||||
|
logger.LogWarning("No provider is selected for the agent.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Assign the provider settings to the agent:
|
// Assign the provider settings to the agent:
|
||||||
logger.LogInformation($"The agent for the retrieval context validation uses the provider '{agentProvider.InstanceName}' ({agentProvider.UsedLLMProvider.ToName()}, confidence={agentProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level.GetName()}).");
|
logger.LogInformation($"The agent for the retrieval context validation uses the provider '{agentProvider.InstanceName}' ({agentProvider.UsedLLMProvider.ToName()}, confidence={agentProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level.GetName()}).");
|
||||||
|
@ -11,7 +11,7 @@ public sealed class AgentTextContentCleaner(ILogger<AgentBase> logger, SettingsM
|
|||||||
|
|
||||||
#region Overrides of AgentBase
|
#region Overrides of AgentBase
|
||||||
|
|
||||||
public override AIStudio.Settings.Provider? ProviderSettings { get; set; }
|
public override AIStudio.Settings.Provider ProviderSettings { get; set; } = AIStudio.Settings.Provider.NONE;
|
||||||
|
|
||||||
protected override Type Type => Type.SYSTEM;
|
protected override Type Type => Type.SYSTEM;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public interface IAgent
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The provider to use for this agent.
|
/// The provider to use for this agent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AIStudio.Settings.Provider? ProviderSettings { get; set; }
|
public Settings.Provider ProviderSettings { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processes a chat thread (i.e., context) and returns the updated thread.
|
/// Processes a chat thread (i.e., context) and returns the updated thread.
|
||||||
|
@ -85,7 +85,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
|
|||||||
|
|
||||||
protected virtual IReadOnlyList<IButtonData> FooterButtons => [];
|
protected virtual IReadOnlyList<IButtonData> FooterButtons => [];
|
||||||
|
|
||||||
protected AIStudio.Settings.Provider providerSettings;
|
protected AIStudio.Settings.Provider providerSettings = Settings.Provider.NONE;
|
||||||
protected MudForm? form;
|
protected MudForm? form;
|
||||||
protected bool inputIsValid;
|
protected bool inputIsValid;
|
||||||
protected Profile currentProfile = Profile.NO_PROFILE;
|
protected Profile currentProfile = Profile.NO_PROFILE;
|
||||||
@ -352,7 +352,7 @@ public abstract partial class AssistantBase<TSettings> : AssistantLowerBase wher
|
|||||||
private async Task InnerResetForm()
|
private async Task InnerResetForm()
|
||||||
{
|
{
|
||||||
this.resultingContentBlock = null;
|
this.resultingContentBlock = null;
|
||||||
this.providerSettings = default;
|
this.providerSettings = Settings.Provider.NONE;
|
||||||
|
|
||||||
await this.JsRuntime.ClearDiv(RESULT_DIV_ID);
|
await this.JsRuntime.ClearDiv(RESULT_DIV_ID);
|
||||||
await this.JsRuntime.ClearDiv(AFTER_RESULT_DIV_ID);
|
await this.JsRuntime.ClearDiv(AFTER_RESULT_DIV_ID);
|
||||||
|
@ -20,7 +20,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
public EventCallback<ChatThread?> ChatThreadChanged { get; set; }
|
public EventCallback<ChatThread?> ChatThreadChanged { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public AIStudio.Settings.Provider Provider { get; set; }
|
public AIStudio.Settings.Provider Provider { get; set; } = AIStudio.Settings.Provider.NONE;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<AIStudio.Settings.Provider> ProviderChanged { get; set; }
|
public EventCallback<AIStudio.Settings.Provider> ProviderChanged { get; set; }
|
||||||
@ -634,7 +634,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
case AddChatProviderBehavior.ADDED_CHATS_USE_LATEST_PROVIDER:
|
case AddChatProviderBehavior.ADDED_CHATS_USE_LATEST_PROVIDER:
|
||||||
if(this.Provider == default)
|
if(this.Provider == AIStudio.Settings.Provider.NONE)
|
||||||
{
|
{
|
||||||
this.Provider = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
|
this.Provider = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
|
||||||
await this.ProviderChanged.InvokeAsync(this.Provider);
|
await this.ProviderChanged.InvokeAsync(this.Provider);
|
||||||
@ -797,7 +797,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LoadingChatProviderBehavior.ALWAYS_USE_LATEST_CHAT_PROVIDER:
|
case LoadingChatProviderBehavior.ALWAYS_USE_LATEST_CHAT_PROVIDER:
|
||||||
if(this.Provider == default)
|
if(this.Provider == AIStudio.Settings.Provider.NONE)
|
||||||
this.Provider = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
|
this.Provider = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,9 @@ public partial class ConfigurationProviderSelection : MSGComponentBase
|
|||||||
foreach (var providerId in this.Data)
|
foreach (var providerId in this.Data)
|
||||||
{
|
{
|
||||||
var provider = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == providerId.Value);
|
var provider = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == providerId.Value);
|
||||||
|
if (provider is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
|
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
|
||||||
yield return providerId;
|
yield return providerId;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public partial class ProviderSelection : MSGComponentBase
|
|||||||
public AssistantBase<NoComponent>? AssistantBase { get; set; }
|
public AssistantBase<NoComponent>? AssistantBase { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public AIStudio.Settings.Provider ProviderSettings { get; set; }
|
public AIStudio.Settings.Provider ProviderSettings { get; set; } = AIStudio.Settings.Provider.NONE;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<AIStudio.Settings.Provider> ProviderSettingsChanged { get; set; }
|
public EventCallback<AIStudio.Settings.Provider> ProviderSettingsChanged { get; set; }
|
||||||
@ -32,6 +32,7 @@ public partial class ProviderSelection : MSGComponentBase
|
|||||||
{
|
{
|
||||||
var minimumLevel = this.SettingsManager.GetMinimumConfidenceLevel(this.AssistantBase?.Component ?? Tools.Components.NONE);
|
var minimumLevel = this.SettingsManager.GetMinimumConfidenceLevel(this.AssistantBase?.Component ?? Tools.Components.NONE);
|
||||||
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
|
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
|
||||||
|
if (provider.UsedLLMProvider != LLMProviders.NONE)
|
||||||
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
|
if (provider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel)
|
||||||
yield return provider;
|
yield return provider;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public partial class ReadWebContent : MSGComponentBase
|
|||||||
public EventCallback<string> ContentChanged { get; set; }
|
public EventCallback<string> ContentChanged { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public AIStudio.Settings.Provider ProviderSettings { get; set; }
|
public AIStudio.Settings.Provider ProviderSettings { get; set; } = AIStudio.Settings.Provider.NONE;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public bool AgentIsRunning { get; set; }
|
public bool AgentIsRunning { get; set; }
|
||||||
@ -34,7 +34,7 @@ public partial class ReadWebContent : MSGComponentBase
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public bool PreselectContentCleanerAgent { get; set; }
|
public bool PreselectContentCleanerAgent { get; set; }
|
||||||
|
|
||||||
private Process<ReadWebContentSteps> process = Process<ReadWebContentSteps>.INSTANCE;
|
private readonly Process<ReadWebContentSteps> process = Process<ReadWebContentSteps>.INSTANCE;
|
||||||
private ProcessStepValue processStep;
|
private ProcessStepValue processStep;
|
||||||
|
|
||||||
private bool showWebContentReader;
|
private bool showWebContentReader;
|
||||||
@ -43,7 +43,7 @@ public partial class ReadWebContent : MSGComponentBase
|
|||||||
private bool urlIsValid;
|
private bool urlIsValid;
|
||||||
private bool isProviderValid;
|
private bool isProviderValid;
|
||||||
|
|
||||||
private AIStudio.Settings.Provider providerSettings;
|
private AIStudio.Settings.Provider providerSettings = AIStudio.Settings.Provider.NONE;
|
||||||
|
|
||||||
#region Overrides of ComponentBase
|
#region Overrides of ComponentBase
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ public partial class ReadWebContent : MSGComponentBase
|
|||||||
this.StateHasChanged();
|
this.StateHasChanged();
|
||||||
markdown = this.HTMLParser.ParseToMarkdown(html);
|
markdown = this.HTMLParser.ParseToMarkdown(html);
|
||||||
|
|
||||||
if (this.useContentCleanerAgent)
|
if (this.useContentCleanerAgent && this.providerSettings != AIStudio.Settings.Provider.NONE)
|
||||||
{
|
{
|
||||||
this.AgentTextContentCleaner.ProviderSettings = this.providerSettings;
|
this.AgentTextContentCleaner.ProviderSettings = this.providerSettings;
|
||||||
var additionalData = new Dictionary<string, string>
|
var additionalData = new Dictionary<string, string>
|
||||||
@ -149,7 +149,7 @@ public partial class ReadWebContent : MSGComponentBase
|
|||||||
|
|
||||||
private string? ValidateProvider(bool shouldUseAgent)
|
private string? ValidateProvider(bool shouldUseAgent)
|
||||||
{
|
{
|
||||||
if(shouldUseAgent && this.providerSettings == default)
|
if(shouldUseAgent && this.providerSettings == AIStudio.Settings.Provider.NONE)
|
||||||
{
|
{
|
||||||
this.isProviderValid = false;
|
this.isProviderValid = false;
|
||||||
return T("Please select a provider to use the cleanup agent.");
|
return T("Please select a provider to use the cleanup agent.");
|
||||||
|
@ -54,6 +54,9 @@ public partial class SettingsPanelProviders : SettingsPanelBase
|
|||||||
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
|
||||||
private async Task EditLLMProvider(AIStudio.Settings.Provider provider)
|
private async Task EditLLMProvider(AIStudio.Settings.Provider provider)
|
||||||
{
|
{
|
||||||
|
if(provider == AIStudio.Settings.Provider.NONE)
|
||||||
|
return;
|
||||||
|
|
||||||
if (provider.IsEnterpriseConfiguration)
|
if (provider.IsEnterpriseConfiguration)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public partial class Chat : MSGComponentBase
|
|||||||
private IDialogService DialogService { get; init; } = null!;
|
private IDialogService DialogService { get; init; } = null!;
|
||||||
|
|
||||||
private ChatThread? chatThread;
|
private ChatThread? chatThread;
|
||||||
private AIStudio.Settings.Provider providerSettings;
|
private AIStudio.Settings.Provider providerSettings = AIStudio.Settings.Provider.NONE;
|
||||||
private bool workspaceOverlayVisible;
|
private bool workspaceOverlayVisible;
|
||||||
private string currentWorkspaceName = string.Empty;
|
private string currentWorkspaceName = string.Empty;
|
||||||
private Workspaces? workspaces;
|
private Workspaces? workspaces;
|
||||||
|
@ -18,7 +18,7 @@ public partial class Writer : MSGComponentBase
|
|||||||
private readonly Timer typeTimer = new(TimeSpan.FromMilliseconds(1_500));
|
private readonly Timer typeTimer = new(TimeSpan.FromMilliseconds(1_500));
|
||||||
|
|
||||||
private MudTextField<string> textField = null!;
|
private MudTextField<string> textField = null!;
|
||||||
private AIStudio.Settings.Provider providerSettings;
|
private AIStudio.Settings.Provider providerSettings = AIStudio.Settings.Provider.NONE;
|
||||||
private ChatThread? chatThread;
|
private ChatThread? chatThread;
|
||||||
private bool isStreaming;
|
private bool isStreaming;
|
||||||
private string userInput = string.Empty;
|
private string userInput = string.Empty;
|
||||||
|
@ -3,7 +3,16 @@ using AIStudio.Tools.PluginSystem;
|
|||||||
|
|
||||||
namespace AIStudio.Settings;
|
namespace AIStudio.Settings;
|
||||||
|
|
||||||
public record ChatTemplate(uint Num, string Id, string Name, string SystemPrompt, string PredefinedUserPrompt, List<ContentBlock> ExampleConversation, bool AllowProfileUsage, bool IsEnterpriseConfiguration = false, Guid EnterpriseConfigurationPluginId = default)
|
public record ChatTemplate(
|
||||||
|
uint Num,
|
||||||
|
string Id,
|
||||||
|
string Name,
|
||||||
|
string SystemPrompt,
|
||||||
|
string PredefinedUserPrompt,
|
||||||
|
List<ContentBlock> ExampleConversation,
|
||||||
|
bool AllowProfileUsage,
|
||||||
|
bool IsEnterpriseConfiguration = false,
|
||||||
|
Guid EnterpriseConfigurationPluginId = default) : IConfigurationObject
|
||||||
{
|
{
|
||||||
public ChatTemplate() : this(0, Guid.Empty.ToString(), string.Empty, string.Empty, string.Empty, [], false)
|
public ChatTemplate() : this(0, Guid.Empty.ToString(), string.Empty, string.Empty, string.Empty, [], false)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,8 @@ using System.Text.Json.Serialization;
|
|||||||
|
|
||||||
using AIStudio.Provider;
|
using AIStudio.Provider;
|
||||||
using AIStudio.Provider.HuggingFace;
|
using AIStudio.Provider.HuggingFace;
|
||||||
|
using AIStudio.Tools.PluginSystem;
|
||||||
|
|
||||||
using Host = AIStudio.Provider.SelfHosted.Host;
|
using Host = AIStudio.Provider.SelfHosted.Host;
|
||||||
|
|
||||||
namespace AIStudio.Settings;
|
namespace AIStudio.Settings;
|
||||||
@ -16,7 +18,7 @@ namespace AIStudio.Settings;
|
|||||||
/// <param name="IsSelfHosted">Whether the provider is self-hosted.</param>
|
/// <param name="IsSelfHosted">Whether the provider is self-hosted.</param>
|
||||||
/// <param name="Hostname">The hostname of the provider. Useful for self-hosted providers.</param>
|
/// <param name="Hostname">The hostname of the provider. Useful for self-hosted providers.</param>
|
||||||
/// <param name="Model">The LLM model to use for chat.</param>
|
/// <param name="Model">The LLM model to use for chat.</param>
|
||||||
public readonly record struct Provider(
|
public record Provider(
|
||||||
uint Num,
|
uint Num,
|
||||||
string Id,
|
string Id,
|
||||||
string InstanceName,
|
string InstanceName,
|
||||||
@ -27,8 +29,23 @@ public readonly record struct Provider(
|
|||||||
Guid EnterpriseConfigurationPluginId = default,
|
Guid EnterpriseConfigurationPluginId = default,
|
||||||
string Hostname = "http://localhost:1234",
|
string Hostname = "http://localhost:1234",
|
||||||
Host Host = Host.NONE,
|
Host Host = Host.NONE,
|
||||||
HFInferenceProvider HFInferenceProvider = HFInferenceProvider.NONE) : ISecretId
|
HFInferenceProvider HFInferenceProvider = HFInferenceProvider.NONE) : ISecretId, IConfigurationObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static readonly Provider NONE = new();
|
||||||
|
|
||||||
|
public Provider() : this(
|
||||||
|
0,
|
||||||
|
Guid.Empty.ToString(),
|
||||||
|
string.Empty,
|
||||||
|
LLMProviders.NONE,
|
||||||
|
default,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
Guid.Empty)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#region Overrides of ValueType
|
#region Overrides of ValueType
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -57,4 +74,10 @@ public readonly record struct Provider(
|
|||||||
public string SecretName => this.InstanceName;
|
public string SecretName => this.InstanceName;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Implementation of IConfigurationObject
|
||||||
|
|
||||||
|
public string Name => this.InstanceName;
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
@ -215,18 +215,18 @@ public sealed class SettingsManager
|
|||||||
return this.ConfigurationData.Providers[0];
|
return this.ConfigurationData.Providers[0];
|
||||||
|
|
||||||
// Is there a current provider with a sufficiently high confidence level?
|
// Is there a current provider with a sufficiently high confidence level?
|
||||||
Provider currentProvider = default;
|
var currentProvider = Provider.NONE;
|
||||||
if (currentProviderId is not null && !string.IsNullOrWhiteSpace(currentProviderId))
|
if (currentProviderId is not null && !string.IsNullOrWhiteSpace(currentProviderId))
|
||||||
{
|
{
|
||||||
var currentProviderProbe = this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == currentProviderId);
|
var currentProviderProbe = this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == currentProviderId);
|
||||||
if (currentProviderProbe.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
|
if (currentProviderProbe is not null && currentProviderProbe.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
|
||||||
currentProvider = currentProviderProbe;
|
currentProvider = currentProviderProbe;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is there a component-preselected provider with a sufficiently high confidence level?
|
// Is there a component-preselected provider with a sufficiently high confidence level?
|
||||||
Provider preselectedProvider = default;
|
var preselectedProvider = Provider.NONE;
|
||||||
var preselectedProviderProbe = component.PreselectedProvider(this);
|
var preselectedProviderProbe = component.PreselectedProvider(this);
|
||||||
if(preselectedProviderProbe != default && preselectedProviderProbe.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
|
if(preselectedProviderProbe != Provider.NONE && preselectedProviderProbe.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel)
|
||||||
preselectedProvider = preselectedProviderProbe;
|
preselectedProvider = preselectedProviderProbe;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -234,14 +234,14 @@ public sealed class SettingsManager
|
|||||||
// and the preselected provider is available and has a confidence level
|
// and the preselected provider is available and has a confidence level
|
||||||
// that is high enough.
|
// that is high enough.
|
||||||
//
|
//
|
||||||
if(usePreselectionBeforeCurrentProvider && preselectedProvider != default)
|
if(usePreselectionBeforeCurrentProvider && preselectedProvider != Provider.NONE)
|
||||||
return preselectedProvider;
|
return preselectedProvider;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Case: The current provider is available and has a confidence level that is
|
// Case: The current provider is available and has a confidence level that is
|
||||||
// high enough.
|
// high enough.
|
||||||
//
|
//
|
||||||
if(currentProvider != default)
|
if(currentProvider != Provider.NONE)
|
||||||
return currentProvider;
|
return currentProvider;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -250,11 +250,11 @@ public sealed class SettingsManager
|
|||||||
// level that is high enough. The preselected provider is available and
|
// level that is high enough. The preselected provider is available and
|
||||||
// has a confidence level that is high enough.
|
// has a confidence level that is high enough.
|
||||||
//
|
//
|
||||||
if(preselectedProvider != default)
|
if(preselectedProvider != Provider.NONE)
|
||||||
return preselectedProvider;
|
return preselectedProvider;
|
||||||
|
|
||||||
// When there is an app-wide preselected provider, and it has a confidence level that is high enough, we return it:
|
// When there is an app-wide preselected provider, and it has a confidence level that is high enough, we return it:
|
||||||
return this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.App.PreselectedProvider && x.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel);
|
return this.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.ConfigurationData.App.PreselectedProvider && x.UsedLLMProvider.GetConfidence(this).Level >= minimumLevel) ?? Provider.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profile GetPreselectedProfile(Tools.Components component)
|
public Profile GetPreselectedProfile(Tools.Components component)
|
||||||
|
@ -113,7 +113,7 @@ public static class ComponentsExtensions
|
|||||||
Components.AGENT_DATA_SOURCE_SELECTION => settingsManager.ConfigurationData.AgentDataSourceSelection.PreselectAgentOptions ? settingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.AgentDataSourceSelection.PreselectedAgentProvider) : default,
|
Components.AGENT_DATA_SOURCE_SELECTION => settingsManager.ConfigurationData.AgentDataSourceSelection.PreselectAgentOptions ? settingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.AgentDataSourceSelection.PreselectedAgentProvider) : default,
|
||||||
Components.AGENT_RETRIEVAL_CONTEXT_VALIDATION => settingsManager.ConfigurationData.AgentRetrievalContextValidation.PreselectAgentOptions ? settingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.AgentRetrievalContextValidation.PreselectedAgentProvider) : default,
|
Components.AGENT_RETRIEVAL_CONTEXT_VALIDATION => settingsManager.ConfigurationData.AgentRetrievalContextValidation.PreselectAgentOptions ? settingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.AgentRetrievalContextValidation.PreselectedAgentProvider) : default,
|
||||||
|
|
||||||
_ => default,
|
_ => Settings.Provider.NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Profile PreselectedProfile(this Components component, SettingsManager settingsManager) => component switch
|
public static Profile PreselectedProfile(this Components component, SettingsManager settingsManager) => component switch
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
namespace AIStudio.Tools.PluginSystem;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a configuration object, such as a chat template or a LLM provider.
|
||||||
|
/// </summary>
|
||||||
|
public interface IConfigurationObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The unique ID of the configuration object.
|
||||||
|
/// </summary>
|
||||||
|
public string Id { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The continuous number of the configuration object.
|
||||||
|
/// </summary>
|
||||||
|
public uint Num { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the configuration object.
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is this configuration object an enterprise configuration?
|
||||||
|
/// </summary>
|
||||||
|
public bool IsEnterpriseConfiguration { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The ID of the enterprise configuration plugin.
|
||||||
|
/// </summary>
|
||||||
|
public Guid EnterpriseConfigurationPluginId { get; }
|
||||||
|
}
|
@ -1,3 +1,8 @@
|
|||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
using AIStudio.Settings;
|
||||||
|
using AIStudio.Settings.DataModel;
|
||||||
|
|
||||||
namespace AIStudio.Tools.PluginSystem;
|
namespace AIStudio.Tools.PluginSystem;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -6,6 +11,9 @@ namespace AIStudio.Tools.PluginSystem;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed record PluginConfigurationObject
|
public sealed record PluginConfigurationObject
|
||||||
{
|
{
|
||||||
|
private static readonly SettingsManager SETTINGS_MANAGER = Program.SERVICE_PROVIDER.GetRequiredService<SettingsManager>();
|
||||||
|
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger<PluginConfigurationObject>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The id of the configuration plugin to which this configuration object belongs.
|
/// The id of the configuration plugin to which this configuration object belongs.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -20,4 +28,55 @@ public sealed record PluginConfigurationObject
|
|||||||
/// The type of the configuration object.
|
/// The type of the configuration object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public required PluginConfigurationObjectType Type { get; init; } = PluginConfigurationObjectType.NONE;
|
public required PluginConfigurationObjectType Type { get; init; } = PluginConfigurationObjectType.NONE;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleans up configuration objects of a specified type that are no longer associated with any available plugin.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TClass">The type of configuration object to clean up.</typeparam>
|
||||||
|
/// <param name="configObjectType">The type of configuration object to process.</param>
|
||||||
|
/// <param name="configObjectSelection">A selection expression to retrieve the configuration objects from the main configuration.</param>
|
||||||
|
/// <param name="availablePlugins">A list of currently available plugins.</param>
|
||||||
|
/// <param name="configObjectList">A list of all existing configuration objects.</param>
|
||||||
|
/// <returns>Returns true if the configuration was altered during cleanup; otherwise, false.</returns>
|
||||||
|
public static bool CleanLeftOverConfigurationObjects<TClass>(
|
||||||
|
PluginConfigurationObjectType configObjectType,
|
||||||
|
Expression<Func<Data, List<TClass>>> configObjectSelection,
|
||||||
|
IList<IAvailablePlugin> availablePlugins,
|
||||||
|
IList<PluginConfigurationObject> configObjectList) where TClass : IConfigurationObject
|
||||||
|
{
|
||||||
|
var configuredObjects = configObjectSelection.Compile()(SETTINGS_MANAGER.ConfigurationData);
|
||||||
|
var leftOverObjects = new List<TClass>();
|
||||||
|
foreach (var configuredObject in configuredObjects)
|
||||||
|
{
|
||||||
|
if(!configuredObject.IsEnterpriseConfiguration)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var configObjectSourcePluginId = configuredObject.EnterpriseConfigurationPluginId;
|
||||||
|
if(configObjectSourcePluginId == Guid.Empty)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var templateSourcePlugin = availablePlugins.FirstOrDefault(plugin => plugin.Id == configObjectSourcePluginId);
|
||||||
|
if(templateSourcePlugin is null)
|
||||||
|
{
|
||||||
|
LOG.LogWarning($"The configured object '{configuredObject.Name}' (id={configuredObject.Id}) is based on a plugin that is not available anymore. Removing the chat template from the settings.");
|
||||||
|
leftOverObjects.Add(configuredObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!configObjectList.Any(configObject =>
|
||||||
|
configObject.Type == configObjectType &&
|
||||||
|
configObject.ConfigPluginId == configObjectSourcePluginId &&
|
||||||
|
configObject.Id.ToString() == configuredObject.Id))
|
||||||
|
{
|
||||||
|
LOG.LogWarning($"The configured object '{configuredObject.Name}' (id={configuredObject.Id}) is not present in the configuration plugin anymore. Removing the chat template from the settings.");
|
||||||
|
leftOverObjects.Add(configuredObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove collected items after enumeration to avoid modifying the collection during iteration:
|
||||||
|
var wasConfigurationChanged = leftOverObjects.Count > 0;
|
||||||
|
foreach (var item in leftOverObjects.Distinct())
|
||||||
|
configuredObjects.Remove(item);
|
||||||
|
|
||||||
|
return wasConfigurationChanged;
|
||||||
|
}
|
||||||
}
|
}
|
@ -92,10 +92,10 @@ public static partial class PluginFactory
|
|||||||
|
|
||||||
case { IsValid: false }:
|
case { IsValid: false }:
|
||||||
LOG.LogError($"Was not able to load plugin '{pluginMainFile}', because the Lua code is not a valid AI Studio plugin. There are {plugin.Issues.Count()} issues to fix. First issue is: {plugin.Issues.FirstOrDefault()}");
|
LOG.LogError($"Was not able to load plugin '{pluginMainFile}', because the Lua code is not a valid AI Studio plugin. There are {plugin.Issues.Count()} issues to fix. First issue is: {plugin.Issues.FirstOrDefault()}");
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
foreach (var pluginIssue in plugin.Issues)
|
foreach (var pluginIssue in plugin.Issues)
|
||||||
LOG.LogError($"Plugin issue: {pluginIssue}");
|
LOG.LogError($"Plugin issue: {pluginIssue}");
|
||||||
#endif
|
#endif
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case { IsMaintained: false }:
|
case { IsMaintained: false }:
|
||||||
@ -125,89 +125,24 @@ public static partial class PluginFactory
|
|||||||
|
|
||||||
//
|
//
|
||||||
// =========================================================
|
// =========================================================
|
||||||
// Next, we have to clean up our settings. It is possible that a configuration plugin was removed.
|
// Next, we have to clean up our settings. It is possible
|
||||||
// We have to remove the related settings as well:
|
// that a configuration plugin was removed. We have to
|
||||||
|
// remove the related settings as well:
|
||||||
// =========================================================
|
// =========================================================
|
||||||
//
|
//
|
||||||
var wasConfigurationChanged = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check LLM providers:
|
// Check LLM providers:
|
||||||
//
|
var wasConfigurationChanged = PluginConfigurationObject.CleanLeftOverConfigurationObjects(PluginConfigurationObjectType.LLM_PROVIDER, x => x.Providers, AVAILABLE_PLUGINS, configObjectList);
|
||||||
#pragma warning disable MWAIS0001
|
|
||||||
var configuredProviders = SETTINGS_MANAGER.ConfigurationData.Providers.ToList();
|
|
||||||
foreach (var configuredProvider in configuredProviders)
|
|
||||||
{
|
|
||||||
if(!configuredProvider.IsEnterpriseConfiguration)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var providerSourcePluginId = configuredProvider.EnterpriseConfigurationPluginId;
|
|
||||||
if(providerSourcePluginId == Guid.Empty)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var providerSourcePlugin = AVAILABLE_PLUGINS.FirstOrDefault(plugin => plugin.Id == providerSourcePluginId);
|
|
||||||
if(providerSourcePlugin is null)
|
|
||||||
{
|
|
||||||
LOG.LogWarning($"The configured LLM provider '{configuredProvider.InstanceName}' (id={configuredProvider.Id}) is based on a plugin that is not available anymore. Removing the provider from the settings.");
|
|
||||||
SETTINGS_MANAGER.ConfigurationData.Providers.Remove(configuredProvider);
|
|
||||||
wasConfigurationChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!configObjectList.Any(configObject =>
|
|
||||||
configObject.Type is PluginConfigurationObjectType.LLM_PROVIDER &&
|
|
||||||
configObject.ConfigPluginId == providerSourcePluginId &&
|
|
||||||
configObject.Id.ToString() == configuredProvider.Id))
|
|
||||||
{
|
|
||||||
LOG.LogWarning($"The configured LLM provider '{configuredProvider.InstanceName}' (id={configuredProvider.Id}) is not present in the configuration plugin anymore. Removing the provider from the settings.");
|
|
||||||
SETTINGS_MANAGER.ConfigurationData.Providers.Remove(configuredProvider);
|
|
||||||
wasConfigurationChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#pragma warning restore MWAIS0001
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check chat templates:
|
// Check chat templates:
|
||||||
//
|
if(PluginConfigurationObject.CleanLeftOverConfigurationObjects(PluginConfigurationObjectType.CHAT_TEMPLATE, x => x.ChatTemplates, AVAILABLE_PLUGINS, configObjectList))
|
||||||
var configuredTemplates = SETTINGS_MANAGER.ConfigurationData.ChatTemplates.ToList();
|
|
||||||
foreach (var configuredTemplate in configuredTemplates)
|
|
||||||
{
|
|
||||||
if(!configuredTemplate.IsEnterpriseConfiguration)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var templateSourcePluginId = configuredTemplate.EnterpriseConfigurationPluginId;
|
|
||||||
if(templateSourcePluginId == Guid.Empty)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var templateSourcePlugin = AVAILABLE_PLUGINS.FirstOrDefault(plugin => plugin.Id == templateSourcePluginId);
|
|
||||||
if(templateSourcePlugin is null)
|
|
||||||
{
|
|
||||||
LOG.LogWarning($"The configured chat template '{configuredTemplate.Name}' (id={configuredTemplate.Id}) is based on a plugin that is not available anymore. Removing the chat template from the settings.");
|
|
||||||
SETTINGS_MANAGER.ConfigurationData.ChatTemplates.Remove(configuredTemplate);
|
|
||||||
wasConfigurationChanged = true;
|
wasConfigurationChanged = true;
|
||||||
}
|
|
||||||
|
|
||||||
if(!configObjectList.Any(configObject =>
|
// Check for update behavior:
|
||||||
configObject.Type is PluginConfigurationObjectType.CHAT_TEMPLATE &&
|
|
||||||
configObject.ConfigPluginId == templateSourcePluginId &&
|
|
||||||
configObject.Id.ToString() == configuredTemplate.Id))
|
|
||||||
{
|
|
||||||
LOG.LogWarning($"The configured chat template '{configuredTemplate.Name}' (id={configuredTemplate.Id}) is not present in the configuration plugin anymore. Removing the chat template from the settings.");
|
|
||||||
SETTINGS_MANAGER.ConfigurationData.ChatTemplates.Remove(configuredTemplate);
|
|
||||||
wasConfigurationChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// ==========================================================
|
|
||||||
// Check all possible settings:
|
|
||||||
// ==========================================================
|
|
||||||
//
|
|
||||||
|
|
||||||
// Check for updates, and if so, how often?
|
|
||||||
if(ManagedConfiguration.IsConfigurationLeftOver<DataApp, UpdateBehavior>(x => x.App, x => x.UpdateBehavior, AVAILABLE_PLUGINS))
|
if(ManagedConfiguration.IsConfigurationLeftOver<DataApp, UpdateBehavior>(x => x.App, x => x.UpdateBehavior, AVAILABLE_PLUGINS))
|
||||||
wasConfigurationChanged = true;
|
wasConfigurationChanged = true;
|
||||||
|
|
||||||
// Allow the user to add providers?
|
// Check for users allowed to added providers:
|
||||||
if(ManagedConfiguration.IsConfigurationLeftOver<DataApp, bool>(x => x.App, x => x.AllowUserToAddProvider, AVAILABLE_PLUGINS))
|
if(ManagedConfiguration.IsConfigurationLeftOver<DataApp, bool>(x => x.App, x => x.AllowUserToAddProvider, AVAILABLE_PLUGINS))
|
||||||
wasConfigurationChanged = true;
|
wasConfigurationChanged = true;
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public sealed class DataSourceService
|
|||||||
// does not mean anything. We cannot filter the data sources by any means.
|
// does not mean anything. We cannot filter the data sources by any means.
|
||||||
// We return an empty list. Better safe than sorry.
|
// We return an empty list. Better safe than sorry.
|
||||||
//
|
//
|
||||||
if (selectedLLMProvider == default)
|
if (selectedLLMProvider == Settings.Provider.NONE)
|
||||||
{
|
{
|
||||||
this.logger.LogWarning("The selected LLM provider is not set. We cannot filter the data sources by any means.");
|
this.logger.LogWarning("The selected LLM provider is not set. We cannot filter the data sources by any means.");
|
||||||
return new([], []);
|
return new([], []);
|
||||||
|
Loading…
Reference in New Issue
Block a user