Add provider selection configuration to DocumentAnalysisAssistant

This commit is contained in:
Thorsten Sommer 2026-01-27 20:31:49 +01:00
parent c863573ad9
commit 459d31b434
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 46 additions and 1 deletions

View File

@ -62,6 +62,8 @@ else
<ConfigurationMinConfidenceSelection Disabled="@(() => this.IsNoPolicySelectedOrProtected)" RestrictToGlobalMinimumConfidence="true" SelectedValue="@(() => this.policyMinimumProviderConfidence)" SelectionUpdateAsync="@(async level => await this.PolicyMinimumConfidenceWasChangedAsync(level))" /> <ConfigurationMinConfidenceSelection Disabled="@(() => this.IsNoPolicySelectedOrProtected)" RestrictToGlobalMinimumConfidence="true" SelectedValue="@(() => this.policyMinimumProviderConfidence)" SelectionUpdateAsync="@(async level => await this.PolicyMinimumConfidenceWasChangedAsync(level))" />
<ConfigurationProviderSelection Component="Components.DOCUMENT_ANALYSIS_ASSISTANT" Data="@this.availableLLMProviders" Disabled="@(() => this.IsNoPolicySelectedOrProtected)" SelectedValue="@(() => this.policyPreselectedProviderId)" SelectionUpdate="@(providerId => this.PolicyPreselectedProviderWasChanged(providerId))"/>
<ConfigurationSelect OptionDescription="@T("Preselect one of your profiles?")" Disabled="@(() => this.IsNoPolicySelected)" SelectedValue="@(() => this.policyPreselectedProfileId)" Data="@ConfigurationSelectDataFactory.GetProfilesData(this.SettingsManager.ConfigurationData.Profiles)" SelectionUpdateAsync="@(async profileId => await this.PolicyPreselectedProfileWasChangedAsync(profileId))" OptionHelp="@T("Select a default profile for this policy. You can still change it later when running the assistant.")" /> <ConfigurationSelect OptionDescription="@T("Preselect one of your profiles?")" Disabled="@(() => this.IsNoPolicySelected)" SelectedValue="@(() => this.policyPreselectedProfileId)" Data="@ConfigurationSelectDataFactory.GetProfilesData(this.SettingsManager.ConfigurationData.Profiles)" SelectionUpdateAsync="@(async profileId => await this.PolicyPreselectedProfileWasChangedAsync(profileId))" OptionHelp="@T("Select a default profile for this policy. You can still change it later when running the assistant.")" />
<MudTextSwitch Disabled="@(this.IsNoPolicySelected || (this.selectedPolicy?.IsManaged ?? true))" Label="@T("Would you like to protect this policy so that you cannot accidentally edit or delete it?")" Value="@this.policyIsProtected" ValueChanged="async state => await this.PolicyProtectionWasChanged(state)" LabelOn="@T("Yes, protect this policy")" LabelOff="@T("No, the policy can be edited")" /> <MudTextSwitch Disabled="@(this.IsNoPolicySelected || (this.selectedPolicy?.IsManaged ?? true))" Label="@T("Would you like to protect this policy so that you cannot accidentally edit or delete it?")" Value="@this.policyIsProtected" ValueChanged="async state => await this.PolicyProtectionWasChanged(state)" LabelOn="@T("Yes, protect this policy")" LabelOff="@T("No, the policy can be edited")" />

View File

@ -173,6 +173,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
this.policyAnalysisRules = string.Empty; this.policyAnalysisRules = string.Empty;
this.policyOutputRules = string.Empty; this.policyOutputRules = string.Empty;
this.policyMinimumProviderConfidence = ConfidenceLevel.NONE; this.policyMinimumProviderConfidence = ConfidenceLevel.NONE;
this.policyPreselectedProviderId = string.Empty;
this.policyPreselectedProfileId = Profile.NO_PROFILE.Id; this.policyPreselectedProfileId = Profile.NO_PROFILE.Id;
} }
} }
@ -187,6 +188,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
this.policyAnalysisRules = this.selectedPolicy.AnalysisRules; this.policyAnalysisRules = this.selectedPolicy.AnalysisRules;
this.policyOutputRules = this.selectedPolicy.OutputRules; this.policyOutputRules = this.selectedPolicy.OutputRules;
this.policyMinimumProviderConfidence = this.selectedPolicy.MinimumProviderConfidence; this.policyMinimumProviderConfidence = this.selectedPolicy.MinimumProviderConfidence;
this.policyPreselectedProviderId = this.selectedPolicy.PreselectedProvider;
this.policyPreselectedProfileId = string.IsNullOrWhiteSpace(this.selectedPolicy.PreselectedProfile) ? Profile.NO_PROFILE.Id : this.selectedPolicy.PreselectedProfile; this.policyPreselectedProfileId = string.IsNullOrWhiteSpace(this.selectedPolicy.PreselectedProfile) ? Profile.NO_PROFILE.Id : this.selectedPolicy.PreselectedProfile;
return true; return true;
@ -213,6 +215,8 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
this.policyDefinitionExpanded = !this.selectedPolicy?.IsProtected ?? true; this.policyDefinitionExpanded = !this.selectedPolicy?.IsProtected ?? true;
await base.OnInitializedAsync(); await base.OnInitializedAsync();
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
this.UpdateProviders();
this.ApplyPolicyPreselection(); this.ApplyPolicyPreselection();
} }
@ -229,7 +233,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
var canEditProtectedFields = force || (!this.selectedPolicy.IsProtected && !this.policyIsProtected); var canEditProtectedFields = force || (!this.selectedPolicy.IsProtected && !this.policyIsProtected);
if (canEditProtectedFields) if (canEditProtectedFields)
{ {
this.selectedPolicy.PreselectedProvider = this.providerSettings.Id; this.selectedPolicy.PreselectedProvider = this.policyPreselectedProviderId;
this.selectedPolicy.PolicyName = this.policyName; this.selectedPolicy.PolicyName = this.policyName;
this.selectedPolicy.PolicyDescription = this.policyDescription; this.selectedPolicy.PolicyDescription = this.policyDescription;
this.selectedPolicy.IsProtected = this.policyIsProtected; this.selectedPolicy.IsProtected = this.policyIsProtected;
@ -249,8 +253,10 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
private string policyAnalysisRules = string.Empty; private string policyAnalysisRules = string.Empty;
private string policyOutputRules = string.Empty; private string policyOutputRules = string.Empty;
private ConfidenceLevel policyMinimumProviderConfidence = ConfidenceLevel.NONE; private ConfidenceLevel policyMinimumProviderConfidence = ConfidenceLevel.NONE;
private string policyPreselectedProviderId = string.Empty;
private string policyPreselectedProfileId = Profile.NO_PROFILE.Id; private string policyPreselectedProfileId = Profile.NO_PROFILE.Id;
private HashSet<FileAttachment> loadedDocumentPaths = []; private HashSet<FileAttachment> loadedDocumentPaths = [];
private readonly List<ConfigurationSelectData<string>> availableLLMProviders = new();
private bool IsNoPolicySelectedOrProtected => this.selectedPolicy is null || this.selectedPolicy.IsProtected; private bool IsNoPolicySelectedOrProtected => this.selectedPolicy is null || this.selectedPolicy.IsProtected;
@ -280,6 +286,14 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
await this.SettingsManager.StoreSettings(); await this.SettingsManager.StoreSettings();
} }
[SuppressMessage("Usage", "MWAIS0001:Direct access to `Providers` is not allowed")]
private void UpdateProviders()
{
this.availableLLMProviders.Clear();
foreach (var provider in this.SettingsManager.ConfigurationData.Providers)
this.availableLLMProviders.Add(new ConfigurationSelectData<string>(provider.InstanceName, provider.Id));
}
private async Task RemovePolicy() private async Task RemovePolicy()
{ {
if(this.selectedPolicy is null) if(this.selectedPolicy is null)
@ -341,6 +355,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
if (this.selectedPolicy is null) if (this.selectedPolicy is null)
return; return;
this.policyPreselectedProviderId = this.selectedPolicy.PreselectedProvider;
var minimumLevel = this.GetPolicyMinimumConfidenceLevel(); var minimumLevel = this.GetPolicyMinimumConfidenceLevel();
// Keep the current provider if it still satisfies the minimum confidence: // Keep the current provider if it still satisfies the minimum confidence:
@ -398,6 +413,17 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
this.ApplyPolicyPreselection(); this.ApplyPolicyPreselection();
} }
private void PolicyPreselectedProviderWasChanged(string providerId)
{
if (this.selectedPolicy is null)
return;
this.policyPreselectedProviderId = providerId;
this.selectedPolicy.PreselectedProvider = providerId;
this.providerSettings = Settings.Provider.NONE;
this.ApplyPolicyPreselection();
}
private async Task PolicyPreselectedProfileWasChangedAsync(string profileId) private async Task PolicyPreselectedProfileWasChangedAsync(string profileId)
{ {
this.policyPreselectedProfileId = profileId; this.policyPreselectedProfileId = profileId;
@ -418,6 +444,23 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
return null; return null;
} }
#region Overrides of MSGComponentBase
protected override Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
{
switch (triggeredEvent)
{
case Event.CONFIGURATION_CHANGED:
this.UpdateProviders();
this.StateHasChanged();
break;
}
return Task.CompletedTask;
}
#endregion
private string? ValidatePolicyDescription(string description) private string? ValidatePolicyDescription(string description)
{ {