Remember chat provider (#217)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2024-11-23 13:04:02 +01:00
1 parent ba6b8d2b3c
commit 0d104f5abc
10 files changed
+120 -9

No files matched your search

+51 -5
View File
@@ -64,7 +64,6 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
// Configure the spellchecking for the user input:
this.SettingsManager.InjectSpellchecking(USER_INPUT_ATTRIBUTES);
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
this.currentProfile = this.SettingsManager.GetPreselectedProfile(Tools.Components.CHAT);
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<ChatThread>(Event.SEND_TO_CHAT).FirstOrDefault();
if (deferredContent is not null)
@@ -106,7 +105,8 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.loadChat = deferredLoading;
this.mustLoadChat = true;
}
this.SelectProviderWhenLoadingChat();
await base.OnInitializedAsync();
}
@@ -115,7 +115,12 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
if (firstRender && this.chatThread is not null && this.mustStoreChat)
{
this.mustStoreChat = false;
await WorkspaceBehaviour.StoreChat(this.chatThread);
if(this.workspaces is not null)
await this.workspaces.StoreChat(this.chatThread);
else
await WorkspaceBehaviour.StoreChat(this.chatThread);
this.currentWorkspaceId = this.chatThread.WorkspaceId;
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
}
@@ -126,8 +131,11 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.chatThread = await WorkspaceBehaviour.LoadChat(this.loadChat);
if(this.chatThread is not null)
{
this.currentWorkspaceName = await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
this.SelectProviderWhenLoadingChat();
}
this.StateHasChanged();
}
@@ -197,6 +205,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
{
this.chatThread = new()
{
SelectedProvider = this.providerSettings.Id,
WorkspaceId = this.currentWorkspaceId,
ChatId = Guid.NewGuid(),
Name = threadName,
@@ -393,6 +402,19 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.isStreaming = false;
this.hasUnsavedChanges = false;
this.userInput = string.Empty;
switch (this.SettingsManager.ConfigurationData.Chat.AddChatProviderBehavior)
{
case AddChatProviderBehavior.ADDED_CHATS_USE_DEFAULT_PROVIDER:
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
break;
default:
case AddChatProviderBehavior.ADDED_CHATS_USE_LATEST_PROVIDER:
if(this.providerSettings == default)
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
break;
}
if (!useSameWorkspace)
{
@@ -404,6 +426,7 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
{
this.chatThread = new()
{
SelectedProvider = this.providerSettings.Id,
WorkspaceId = this.currentWorkspaceId,
ChatId = Guid.NewGuid(),
Name = string.Empty,
@@ -486,7 +509,9 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.userInput = string.Empty;
this.currentWorkspaceId = this.chatThread?.WorkspaceId ?? Guid.Empty;
this.currentWorkspaceName = this.chatThread is null ? string.Empty : await WorkspaceBehaviour.LoadWorkspaceName(this.chatThread.WorkspaceId);
this.SelectProviderWhenLoadingChat();
this.userInput = string.Empty;
if (this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading)
{
@@ -506,6 +531,27 @@ public partial class Chat : MSGComponentBase, IAsyncDisposable
this.chatThread = null;
}
private void SelectProviderWhenLoadingChat()
{
var chatProvider = this.chatThread?.SelectedProvider;
switch (this.SettingsManager.ConfigurationData.Chat.LoadingProviderBehavior)
{
default:
case LoadingChatProviderBehavior.USE_CHAT_PROVIDER_IF_AVAILABLE:
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT, chatProvider);
break;
case LoadingChatProviderBehavior.ALWAYS_USE_DEFAULT_CHAT_PROVIDER:
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
break;
case LoadingChatProviderBehavior.ALWAYS_USE_LATEST_CHAT_PROVIDER:
if(this.providerSettings == default)
this.providerSettings = this.SettingsManager.GetPreselectedProvider(Tools.Components.CHAT);
break;
}
}
#region Overrides of MSGComponentBase
public override async Task ProcessIncomingMessage<T>(ComponentBase? sendingComponent, Event triggeredEvent, T? data) where T : default
@@ -193,6 +193,9 @@
<ExpansionPanel HeaderIcon="@Icons.Material.Filled.Chat" HeaderText="Chat Options">
<ConfigurationSelect OptionDescription="Shortcut to send input" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Chat.ShortcutSendBehavior)" Data="@ConfigurationSelectDataFactory.GetSendBehaviorData()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Chat.ShortcutSendBehavior = selectedValue)" OptionHelp="Do you want to use any shortcut to send your input?"/>
<ConfigurationOption OptionDescription="Show the latest message after loading?" LabelOn="Latest message is shown, after loading a chat" LabelOff="First (oldest) message is shown, after loading a chat" State="@(() => this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.Chat.ShowLatestMessageAfterLoading = updatedState)" OptionHelp="When enabled, the latest message is shown after loading a chat. When disabled, the first (oldest) message is shown."/>
<ConfigurationSelect OptionDescription="Provider selection when creating new chats" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Chat.AddChatProviderBehavior)" Data="@ConfigurationSelectDataFactory.GetAddChatProviderBehavior()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Chat.AddChatProviderBehavior = selectedValue)" OptionHelp="Control how the LLM provider for added chats is selected."/>
<ConfigurationSelect OptionDescription="Provider selection when loading a chat and sending assistant results to chat" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Chat.LoadingProviderBehavior)" Data="@ConfigurationSelectDataFactory.GetLoadingChatProviderBehavior()" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Chat.LoadingProviderBehavior = selectedValue)" OptionHelp="Control how the LLM provider for loaded chats is selected and when assistant results are sent to chat."/>
<MudPaper Class="pa-3 mb-8 border-dashed border rounded-lg">
<ConfigurationOption OptionDescription="Preselect chat options?" LabelOn="Chat options are preselected" LabelOff="No chat options are preselected" State="@(() => this.SettingsManager.ConfigurationData.Chat.PreselectOptions)" StateUpdate="@(updatedState => this.SettingsManager.ConfigurationData.Chat.PreselectOptions = updatedState)" OptionHelp="When enabled, you can preselect chat options. This is might be useful when you prefer a specific provider."/>
<ConfigurationProviderSelection Data="@this.availableProviders" Disabled="@(() => !this.SettingsManager.ConfigurationData.Chat.PreselectOptions)" SelectedValue="@(() => this.SettingsManager.ConfigurationData.Chat.PreselectedProvider)" SelectionUpdate="@(selectedValue => this.SettingsManager.ConfigurationData.Chat.PreselectedProvider = selectedValue)"/>