From 64e32cd1fa8ccceeaaa301790240e1508706397f Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 5 Jan 2025 14:22:31 +0100 Subject: [PATCH] Refactored profile settings --- .../Settings/SettingsPanelProfiles.razor | 50 +++++++++++++ .../Settings/SettingsPanelProfiles.razor.cs | 72 +++++++++++++++++++ app/MindWork AI Studio/Pages/Settings.razor | 50 +------------ .../Pages/Settings.razor.cs | 68 ------------------ 4 files changed, 123 insertions(+), 117 deletions(-) create mode 100644 app/MindWork AI Studio/Components/Settings/SettingsPanelProfiles.razor create mode 100644 app/MindWork AI Studio/Components/Settings/SettingsPanelProfiles.razor.cs diff --git a/app/MindWork AI Studio/Components/Settings/SettingsPanelProfiles.razor b/app/MindWork AI Studio/Components/Settings/SettingsPanelProfiles.razor new file mode 100644 index 00000000..924eb773 --- /dev/null +++ b/app/MindWork AI Studio/Components/Settings/SettingsPanelProfiles.razor @@ -0,0 +1,50 @@ +@inherits SettingsPanelBase + + + Your Profiles + + Store personal data about yourself in various profiles so that the AIs know your personal context. + This saves you from having to explain your context each time, for example, in every chat. When you + have different roles, you can create a profile for each role. + + + + Are you a project manager in a research facility? You might want to create a profile for your project + management activities, one for your scientific work, and a profile for when you need to write program + code. In these profiles, you can record how much experience you have or which methods you like or + dislike using. Later, you can choose when and where you want to use each profile. + + + + + + + + + # + Profile Name + Actions + + + @context.Num + @context.Name + + + Edit + + + Delete + + + + + + @if(this.SettingsManager.ConfigurationData.Profiles.Count == 0) + { + No profiles configured yet. + } + + + Add Profile + + \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Settings/SettingsPanelProfiles.razor.cs b/app/MindWork AI Studio/Components/Settings/SettingsPanelProfiles.razor.cs new file mode 100644 index 00000000..15b3214d --- /dev/null +++ b/app/MindWork AI Studio/Components/Settings/SettingsPanelProfiles.razor.cs @@ -0,0 +1,72 @@ +using AIStudio.Dialogs; +using AIStudio.Settings; + +using DialogOptions = AIStudio.Dialogs.DialogOptions; + +namespace AIStudio.Components.Settings; + +public partial class SettingsPanelProfiles : SettingsPanelBase +{ + private async Task AddProfile() + { + var dialogParameters = new DialogParameters + { + { x => x.IsEditing, false }, + }; + + var dialogReference = await this.DialogService.ShowAsync("Add Profile", dialogParameters, DialogOptions.FULLSCREEN); + var dialogResult = await dialogReference.Result; + if (dialogResult is null || dialogResult.Canceled) + return; + + var addedProfile = (Profile)dialogResult.Data!; + addedProfile = addedProfile with { Num = this.SettingsManager.ConfigurationData.NextProfileNum++ }; + + this.SettingsManager.ConfigurationData.Profiles.Add(addedProfile); + + await this.SettingsManager.StoreSettings(); + await this.MessageBus.SendMessage(this, Event.CONFIGURATION_CHANGED); + } + + private async Task EditProfile(Profile profile) + { + var dialogParameters = new DialogParameters + { + { x => x.DataNum, profile.Num }, + { x => x.DataId, profile.Id }, + { x => x.DataName, profile.Name }, + { x => x.DataNeedToKnow, profile.NeedToKnow }, + { x => x.DataActions, profile.Actions }, + { x => x.IsEditing, true }, + }; + + var dialogReference = await this.DialogService.ShowAsync("Edit Profile", dialogParameters, DialogOptions.FULLSCREEN); + var dialogResult = await dialogReference.Result; + if (dialogResult is null || dialogResult.Canceled) + return; + + var editedProfile = (Profile)dialogResult.Data!; + this.SettingsManager.ConfigurationData.Profiles[this.SettingsManager.ConfigurationData.Profiles.IndexOf(profile)] = editedProfile; + + await this.SettingsManager.StoreSettings(); + await this.MessageBus.SendMessage(this, Event.CONFIGURATION_CHANGED); + } + + private async Task DeleteProfile(Profile profile) + { + var dialogParameters = new DialogParameters + { + { "Message", $"Are you sure you want to delete the profile '{profile.Name}'?" }, + }; + + var dialogReference = await this.DialogService.ShowAsync("Delete Profile", dialogParameters, DialogOptions.FULLSCREEN); + var dialogResult = await dialogReference.Result; + if (dialogResult is null || dialogResult.Canceled) + return; + + this.SettingsManager.ConfigurationData.Profiles.Remove(profile); + await this.SettingsManager.StoreSettings(); + + await this.MessageBus.SendMessage(this, Event.CONFIGURATION_CHANGED); + } +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Pages/Settings.razor b/app/MindWork AI Studio/Pages/Settings.razor index 08a0d10c..ea3c42f5 100644 --- a/app/MindWork AI Studio/Pages/Settings.razor +++ b/app/MindWork AI Studio/Pages/Settings.razor @@ -197,55 +197,7 @@ } - - Your Profiles - - Store personal data about yourself in various profiles so that the AIs know your personal context. - This saves you from having to explain your context each time, for example, in every chat. When you - have different roles, you can create a profile for each role. - - - - Are you a project manager in a research facility? You might want to create a profile for your project - management activities, one for your scientific work, and a profile for when you need to write program - code. In these profiles, you can record how much experience you have or which methods you like or - dislike using. Later, you can choose when and where you want to use each profile. - - - - - - - - - # - Profile Name - Actions - - - @context.Num - @context.Name - - - Edit - - - Delete - - - - - - @if(this.SettingsManager.ConfigurationData.Profiles.Count == 0) - { - No profiles configured yet. - } - - - Add Profile - - - + diff --git a/app/MindWork AI Studio/Pages/Settings.razor.cs b/app/MindWork AI Studio/Pages/Settings.razor.cs index 0f9bb61d..cadcb35b 100644 --- a/app/MindWork AI Studio/Pages/Settings.razor.cs +++ b/app/MindWork AI Studio/Pages/Settings.razor.cs @@ -1,7 +1,6 @@ using AIStudio.Dialogs; using AIStudio.Provider; using AIStudio.Settings; -using AIStudio.Settings.DataModel; using Microsoft.AspNetCore.Components; @@ -257,73 +256,6 @@ public partial class Settings : ComponentBase, IMessageBusReceiver, IDisposable this.availableEmbeddingProviders.Add(new (provider.Name, provider.Id)); } - #endregion - - #region Profile related - - private async Task AddProfile() - { - var dialogParameters = new DialogParameters - { - { x => x.IsEditing, false }, - }; - - var dialogReference = await this.DialogService.ShowAsync("Add Profile", dialogParameters, DialogOptions.FULLSCREEN); - var dialogResult = await dialogReference.Result; - if (dialogResult is null || dialogResult.Canceled) - return; - - var addedProfile = (Profile)dialogResult.Data!; - addedProfile = addedProfile with { Num = this.SettingsManager.ConfigurationData.NextProfileNum++ }; - - this.SettingsManager.ConfigurationData.Profiles.Add(addedProfile); - - await this.SettingsManager.StoreSettings(); - await this.MessageBus.SendMessage(this, Event.CONFIGURATION_CHANGED); - } - - private async Task EditProfile(Profile profile) - { - var dialogParameters = new DialogParameters - { - { x => x.DataNum, profile.Num }, - { x => x.DataId, profile.Id }, - { x => x.DataName, profile.Name }, - { x => x.DataNeedToKnow, profile.NeedToKnow }, - { x => x.DataActions, profile.Actions }, - { x => x.IsEditing, true }, - }; - - var dialogReference = await this.DialogService.ShowAsync("Edit Profile", dialogParameters, DialogOptions.FULLSCREEN); - var dialogResult = await dialogReference.Result; - if (dialogResult is null || dialogResult.Canceled) - return; - - var editedProfile = (Profile)dialogResult.Data!; - this.SettingsManager.ConfigurationData.Profiles[this.SettingsManager.ConfigurationData.Profiles.IndexOf(profile)] = editedProfile; - - await this.SettingsManager.StoreSettings(); - await this.MessageBus.SendMessage(this, Event.CONFIGURATION_CHANGED); - } - - private async Task DeleteProfile(Profile profile) - { - var dialogParameters = new DialogParameters - { - { "Message", $"Are you sure you want to delete the profile '{profile.Name}'?" }, - }; - - var dialogReference = await this.DialogService.ShowAsync("Delete Profile", dialogParameters, DialogOptions.FULLSCREEN); - var dialogResult = await dialogReference.Result; - if (dialogResult is null || dialogResult.Canceled) - return; - - this.SettingsManager.ConfigurationData.Profiles.Remove(profile); - await this.SettingsManager.StoreSettings(); - - await this.MessageBus.SendMessage(this, Event.CONFIGURATION_CHANGED); - } - #endregion #region Implementation of IMessageBusReceiver