From 740fab37cf39f242e628ca28d6bb9c89fa20cd36 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 27 Jan 2026 19:41:47 +0100 Subject: [PATCH] Initial support for confidence & standard profile --- .../DocumentAnalysisAssistant.razor | 7 +- .../DocumentAnalysisAssistant.razor.cs | 110 +++++++++++++++--- .../Tools/ComponentsExtensions.cs | 16 ++- 3 files changed, 112 insertions(+), 21 deletions(-) diff --git a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor index 576664bb..fd1f2fb1 100644 --- a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor +++ b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor @@ -1,6 +1,7 @@ @attribute [Route(Routes.ASSISTANT_DOCUMENT_ANALYSIS)] @inherits AssistantBaseCore +@using AIStudio.Settings @using AIStudio.Settings.DataModel @@ -61,6 +62,10 @@ else + + + + @T("Analysis and output rules") @@ -117,4 +122,4 @@ else - \ No newline at end of file + diff --git a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs index 7c886b21..a744c7bb 100644 --- a/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs +++ b/app/MindWork AI Studio/Assistants/DocumentAnalysis/DocumentAnalysisAssistant.razor.cs @@ -1,8 +1,11 @@ using System.Text; +using System.Diagnostics.CodeAnalysis; using AIStudio.Chat; using AIStudio.Dialogs; using AIStudio.Dialogs.Settings; +using AIStudio.Provider; +using AIStudio.Settings; using AIStudio.Settings.DataModel; using Microsoft.AspNetCore.Components; @@ -169,6 +172,8 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore loadedDocumentPaths = []; private bool IsNoPolicySelectedOrProtected => this.selectedPolicy is null || this.selectedPolicy.IsProtected; @@ -250,6 +261,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore= minimumLevel) + { + this.currentProfile = this.ResolveProfileSelection(); + return; + } + + // Try to apply the policy preselection: + var policyProvider = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.selectedPolicy.PreselectedProvider); + if (policyProvider is not null && policyProvider.UsedLLMProvider.GetConfidence(this.SettingsManager).Level >= minimumLevel) + { + this.providerSettings = policyProvider; + this.currentProfile = this.ResolveProfileSelection(); + return; + } + + this.providerSettings = this.SettingsManager.GetPreselectedProvider(this.Component, this.providerSettings.Id); + this.currentProfile = this.ResolveProfileSelection(); + } + + private ConfidenceLevel GetPolicyMinimumConfidenceLevel() + { + var minimumLevel = ConfidenceLevel.NONE; + var llmSettings = this.SettingsManager.ConfigurationData.LLMProviders; + var enforceGlobalMinimumConfidence = llmSettings is { EnforceGlobalMinimumConfidence: true, GlobalMinimumConfidence: not ConfidenceLevel.NONE and not ConfidenceLevel.UNKNOWN }; + if (enforceGlobalMinimumConfidence) + minimumLevel = llmSettings.GlobalMinimumConfidence; + + if (this.selectedPolicy is not null && this.selectedPolicy.MinimumProviderConfidence > minimumLevel) + minimumLevel = this.selectedPolicy.MinimumProviderConfidence; + + return minimumLevel; + } + + private Profile ResolveProfileSelection() + { + if (this.selectedPolicy is not null && !string.IsNullOrWhiteSpace(this.selectedPolicy.PreselectedProfile)) + { + var policyProfile = this.SettingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == this.selectedPolicy.PreselectedProfile); + if (policyProfile is not null) + return policyProfile; + } + + return this.SettingsManager.GetPreselectedProfile(this.Component); + } + + private async Task PolicyMinimumConfidenceWasChangedAsync(ConfidenceLevel level) + { + this.policyMinimumProviderConfidence = level; + await this.AutoSave(); + + this.ApplyPolicyPreselection(); + } + + private async Task PolicyPreselectedProfileWasChangedAsync(string profileId) + { + this.policyPreselectedProfileId = profileId; + this.currentProfile = this.ResolveProfileSelection(); + await this.AutoSave(); + } private string? ValidatePolicyName(string name) { diff --git a/app/MindWork AI Studio/Tools/ComponentsExtensions.cs b/app/MindWork AI Studio/Tools/ComponentsExtensions.cs index 6d851beb..721ae79d 100644 --- a/app/MindWork AI Studio/Tools/ComponentsExtensions.cs +++ b/app/MindWork AI Studio/Tools/ComponentsExtensions.cs @@ -88,8 +88,9 @@ public static class ComponentsExtensions Components.BIAS_DAY_ASSISTANT => settingsManager.ConfigurationData.BiasOfTheDay.PreselectOptions ? settingsManager.ConfigurationData.BiasOfTheDay.MinimumProviderConfidence : default, Components.ERI_ASSISTANT => settingsManager.ConfigurationData.ERI.PreselectOptions ? settingsManager.ConfigurationData.ERI.MinimumProviderConfidence : default, - #warning Add minimum confidence for DOCUMENT_ANALYSIS_ASSISTANT: - //Components.DOCUMENT_ANALYSIS_ASSISTANT => settingsManager.ConfigurationData.DocumentAnalysis.PreselectOptions ? settingsManager.ConfigurationData.DocumentAnalysis.MinimumProviderConfidence : default, + // The minimum confidence for the Document Analysis Assistant is set per policy. + // We do this inside the Document Analysis Assistant component: + Components.DOCUMENT_ANALYSIS_ASSISTANT => ConfidenceLevel.NONE, _ => default, }; @@ -115,8 +116,9 @@ public static class ComponentsExtensions Components.ERI_ASSISTANT => settingsManager.ConfigurationData.ERI.PreselectOptions ? settingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.ERI.PreselectedProvider) : null, Components.I18N_ASSISTANT => settingsManager.ConfigurationData.I18N.PreselectOptions ? settingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.I18N.PreselectedProvider) : null, - #warning Add preselected provider for DOCUMENT_ANALYSIS_ASSISTANT: - //Components.DOCUMENT_ANALYSIS_ASSISTANT => settingsManager.ConfigurationData.DocumentAnalysis.PreselectOptions ? settingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.DocumentAnalysis.PreselectedProvider) : null, + // The Document Analysis Assistant does not have a preselected provider at the component level. + // The provider is selected per policy instead. We do this inside the Document Analysis Assistant component. + Components.DOCUMENT_ANALYSIS_ASSISTANT => Settings.Provider.NONE, Components.CHAT => settingsManager.ConfigurationData.Chat.PreselectOptions ? settingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.Chat.PreselectedProvider) : null, @@ -132,8 +134,6 @@ public static class ComponentsExtensions public static Profile PreselectedProfile(this Components component, SettingsManager settingsManager) => component switch { - #warning Add preselected profile for DOCUMENT_ANALYSIS_ASSISTANT: - // Components.DOCUMENT_ANALYSIS_ASSISTANT => settingsManager.ConfigurationData.DocumentAnalysis.PreselectOptions ? settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.DocumentAnalysis.PreselectedProfile) : default, Components.AGENDA_ASSISTANT => settingsManager.ConfigurationData.Agenda.PreselectOptions ? settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.Agenda.PreselectedProfile) ?? Profile.NO_PROFILE : Profile.NO_PROFILE, Components.CODING_ASSISTANT => settingsManager.ConfigurationData.Coding.PreselectOptions ? settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.Coding.PreselectedProfile) ?? Profile.NO_PROFILE : Profile.NO_PROFILE, Components.EMAIL_ASSISTANT => settingsManager.ConfigurationData.EMail.PreselectOptions ? settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.EMail.PreselectedProfile) ?? Profile.NO_PROFILE : Profile.NO_PROFILE, @@ -142,6 +142,10 @@ public static class ComponentsExtensions Components.BIAS_DAY_ASSISTANT => settingsManager.ConfigurationData.BiasOfTheDay.PreselectOptions ? settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.BiasOfTheDay.PreselectedProfile) ?? Profile.NO_PROFILE : Profile.NO_PROFILE, Components.ERI_ASSISTANT => settingsManager.ConfigurationData.ERI.PreselectOptions ? settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.ERI.PreselectedProfile) ?? Profile.NO_PROFILE : Profile.NO_PROFILE, + // The Document Analysis Assistant does not have a preselected profile at the component level. + // The profile is selected per policy instead. We do this inside the Document Analysis Assistant component: + Components.DOCUMENT_ANALYSIS_ASSISTANT => Profile.NO_PROFILE, + Components.CHAT => settingsManager.ConfigurationData.Chat.PreselectOptions ? settingsManager.ConfigurationData.Profiles.FirstOrDefault(x => x.Id == settingsManager.ConfigurationData.Chat.PreselectedProfile) ?? Profile.NO_PROFILE : Profile.NO_PROFILE, _ => Profile.NO_PROFILE,