From 906219dd257eb6019c301b6eff03d68d9d9ef262 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 16 Feb 2025 23:59:49 +0100 Subject: [PATCH] Store the AI-selected data sources to the chat thread so that the user can see the selection --- app/MindWork AI Studio/Chat/ContentText.cs | 3 +++ app/MindWork AI Studio/Components/ChatComponent.razor.cs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/app/MindWork AI Studio/Chat/ContentText.cs b/app/MindWork AI Studio/Chat/ContentText.cs index cdfd2acf..8275c245 100644 --- a/app/MindWork AI Studio/Chat/ContentText.cs +++ b/app/MindWork AI Studio/Chat/ContentText.cs @@ -154,6 +154,9 @@ public sealed class ContentText : IContent // Transform the selected data sources to the actual data sources. selectedDataSources = aiSelectedDataSources.Select(x => settings.ConfigurationData.DataSources.FirstOrDefault(ds => ds.Id == x.Id)).Where(ds => ds is not null).ToList()!; } + + // Store the changes in the chat thread: + chatThread.DataSourceOptions.PreselectedDataSourceIds = selectedDataSources.Select(ds => ds.Id).ToList(); } } else diff --git a/app/MindWork AI Studio/Components/ChatComponent.razor.cs b/app/MindWork AI Studio/Components/ChatComponent.razor.cs index 10b8bd79..78721864 100644 --- a/app/MindWork AI Studio/Components/ChatComponent.razor.cs +++ b/app/MindWork AI Studio/Components/ChatComponent.razor.cs @@ -481,6 +481,14 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable // Disable the stream state: this.isStreaming = false; + + // Update the data source options. This is useful when + // the AI is responsible for selecting the data source. + // The user can then see the selected data source: + if(this.ChatThread?.DataSourceOptions.AutomaticDataSourceSelection ?? false) + this.dataSourceSelectionComponent?.ChangeOptionWithoutSaving(this.ChatThread!.DataSourceOptions); + + // Update the UI: this.StateHasChanged(); }