From f8e06faea582e0fb6e0ead10c4c133425dac4c86 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 18 Aug 2024 21:48:35 +0200 Subject: [PATCH] Send to chat (#77) --- app/MindWork AI Studio/Chat/ChatThread.cs | 2 +- app/MindWork AI Studio/Chat/SystemPrompts.cs | 6 ++ .../Components/AssistantBase.razor | 19 ++-- .../Components/AssistantBase.razor.cs | 62 ++++++++++--- .../Components/Blocks/Changelog.Logs.cs | 1 + .../Pages/Agenda/AssistantAgenda.razor.cs | 91 ++++++++++++++----- .../Components/Pages/Chat.razor.cs | 20 +++- .../Pages/Coding/AssistantCoding.razor.cs | 42 +++++++-- .../AssistantGrammarSpelling.razor.cs | 34 ++++++- .../IconFinder/AssistantIconFinder.razor.cs | 22 ++++- .../AssistantRewriteImprove.razor.cs | 35 ++++++- .../Pages/{SendToAssistant.cs => SendTo.cs} | 4 +- .../Pages/SendToAssistantExtensions.cs | 20 ---- .../Components/Pages/SendToExtensions.cs | 22 +++++ .../AssistantTextSummarizer.razor.cs | 45 +++++++-- .../Translation/AssistantTranslation.razor.cs | 43 +++++++-- app/MindWork AI Studio/Tools/Event.cs | 3 +- .../Tools/JsRuntimeExtensions.cs | 5 + app/MindWork AI Studio/Tools/SendToButton.cs | 4 +- app/MindWork AI Studio/packages.lock.json | 2 +- app/MindWork AI Studio/wwwroot/app.js | 5 + .../wwwroot/changelog/v0.8.10.md | 4 + metadata.txt | 8 +- runtime/Cargo.lock | 2 +- runtime/Cargo.toml | 2 +- runtime/tauri.conf.json | 2 +- 26 files changed, 384 insertions(+), 121 deletions(-) create mode 100644 app/MindWork AI Studio/Chat/SystemPrompts.cs rename app/MindWork AI Studio/Components/Pages/{SendToAssistant.cs => SendTo.cs} (87%) delete mode 100644 app/MindWork AI Studio/Components/Pages/SendToAssistantExtensions.cs create mode 100644 app/MindWork AI Studio/Components/Pages/SendToExtensions.cs create mode 100644 app/MindWork AI Studio/wwwroot/changelog/v0.8.10.md diff --git a/app/MindWork AI Studio/Chat/ChatThread.cs b/app/MindWork AI Studio/Chat/ChatThread.cs index 8c5f3819..ae369e86 100644 --- a/app/MindWork AI Studio/Chat/ChatThread.cs +++ b/app/MindWork AI Studio/Chat/ChatThread.cs @@ -3,7 +3,7 @@ namespace AIStudio.Chat; /// /// Data structure for a chat thread. /// -public sealed class ChatThread +public sealed record ChatThread { /// /// The unique identifier of the chat thread. diff --git a/app/MindWork AI Studio/Chat/SystemPrompts.cs b/app/MindWork AI Studio/Chat/SystemPrompts.cs new file mode 100644 index 00000000..0ed69b9f --- /dev/null +++ b/app/MindWork AI Studio/Chat/SystemPrompts.cs @@ -0,0 +1,6 @@ +namespace AIStudio.Chat; + +public static class SystemPrompts +{ + public const string DEFAULT = "You are a helpful assistant!"; +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/AssistantBase.razor b/app/MindWork AI Studio/Components/AssistantBase.razor index 363cc220..a0a5b26a 100644 --- a/app/MindWork AI Studio/Components/AssistantBase.razor +++ b/app/MindWork AI Studio/Components/AssistantBase.razor @@ -2,22 +2,22 @@ @using AIStudio.Components.Pages @using AIStudio.Tools - @this.Title + @(this.Title) - + - @this.Description + @(this.Description) @if (this.Body is not null) { - @this.Body + @(this.Body) } - + @if (this.ShowDedicatedProgress && this.isProcessing) { @@ -26,7 +26,7 @@
@if (this.ShowResult && this.resultingContentBlock is not null) { - + }
@@ -56,9 +56,9 @@ case SendToButton sendToButton: - @foreach (var assistant in Enum.GetValues().OrderBy(n => n.Name().Length)) + @foreach (var assistant in Enum.GetValues().OrderBy(n => n.Name().Length)) { - if(assistant is Pages.SendToAssistant.NONE || sendToButton.Self == assistant) + if(assistant is SendTo.NONE || sendToButton.Self == assistant) continue; @@ -69,6 +69,9 @@ break; } } + + Reset + }
diff --git a/app/MindWork AI Studio/Components/AssistantBase.razor.cs b/app/MindWork AI Studio/Components/AssistantBase.razor.cs index 494db193..a4441f99 100644 --- a/app/MindWork AI Studio/Components/AssistantBase.razor.cs +++ b/app/MindWork AI Studio/Components/AssistantBase.razor.cs @@ -38,6 +38,10 @@ public abstract partial class AssistantBase : ComponentBase protected abstract string Description { get; } protected abstract string SystemPrompt { get; } + + protected abstract void ResetFrom(); + + protected abstract bool MightPreselectValues(); private protected virtual RenderFragment? Body => null; @@ -45,6 +49,8 @@ public abstract partial class AssistantBase : ComponentBase protected virtual bool ShowDedicatedProgress => false; + protected virtual ChatThread ConvertToChatThread => this.chatThread ?? new(); + protected virtual IReadOnlyList FooterButtons => []; protected static readonly Dictionary USER_INPUT_ATTRIBUTES = new(); @@ -53,7 +59,7 @@ public abstract partial class AssistantBase : ComponentBase protected MudForm? form; protected bool inputIsValid; - private ChatThread? chatThread; + protected ChatThread? chatThread; private ContentBlock? resultingContentBlock; private string[] inputIssues = []; private bool isProcessing; @@ -164,11 +170,11 @@ protected async Task CopyToClipboard(string text) return icon; } - private Task SendToAssistant(SendToAssistant assistant, SendToButton sendToButton) + private Task SendToAssistant(SendTo destination, SendToButton sendToButton) { var contentToSend = sendToButton.UseResultingContentBlockData switch { - false => sendToButton.GetData(), + false => sendToButton.GetText(), true => this.resultingContentBlock?.Content switch { ContentText textBlock => textBlock.Text, @@ -176,21 +182,51 @@ private Task SendToAssistant(SendToAssistant assistant, SendToButton sendToButto }, }; - var (eventItem, path) = assistant switch + var (eventItem, path) = destination switch { - Pages.SendToAssistant.AGENDA_ASSISTANT => (Event.SEND_TO_AGENDA_ASSISTANT, Path.ASSISTANT_AGENDA), - Pages.SendToAssistant.CODING_ASSISTANT => (Event.SEND_TO_CODING_ASSISTANT, Path.ASSISTANT_CODING), - Pages.SendToAssistant.REWRITE_ASSISTANT => (Event.SEND_TO_REWRITE_ASSISTANT, Path.ASSISTANT_REWRITE), - Pages.SendToAssistant.TRANSLATION_ASSISTANT => (Event.SEND_TO_TRANSLATION_ASSISTANT, Path.ASSISTANT_TRANSLATION), - Pages.SendToAssistant.ICON_FINDER_ASSISTANT => (Event.SEND_TO_ICON_FINDER_ASSISTANT, Path.ASSISTANT_ICON_FINDER), - Pages.SendToAssistant.GRAMMAR_SPELLING_ASSISTANT => (Event.SEND_TO_GRAMMAR_SPELLING_ASSISTANT, Path.ASSISTANT_GRAMMAR_SPELLING), - Pages.SendToAssistant.TEXT_SUMMARIZER_ASSISTANT => (Event.SEND_TO_TEXT_SUMMARIZER_ASSISTANT, Path.ASSISTANT_SUMMARIZER), + SendTo.AGENDA_ASSISTANT => (Event.SEND_TO_AGENDA_ASSISTANT, Path.ASSISTANT_AGENDA), + SendTo.CODING_ASSISTANT => (Event.SEND_TO_CODING_ASSISTANT, Path.ASSISTANT_CODING), + SendTo.REWRITE_ASSISTANT => (Event.SEND_TO_REWRITE_ASSISTANT, Path.ASSISTANT_REWRITE), + SendTo.TRANSLATION_ASSISTANT => (Event.SEND_TO_TRANSLATION_ASSISTANT, Path.ASSISTANT_TRANSLATION), + SendTo.ICON_FINDER_ASSISTANT => (Event.SEND_TO_ICON_FINDER_ASSISTANT, Path.ASSISTANT_ICON_FINDER), + SendTo.GRAMMAR_SPELLING_ASSISTANT => (Event.SEND_TO_GRAMMAR_SPELLING_ASSISTANT, Path.ASSISTANT_GRAMMAR_SPELLING), + SendTo.TEXT_SUMMARIZER_ASSISTANT => (Event.SEND_TO_TEXT_SUMMARIZER_ASSISTANT, Path.ASSISTANT_SUMMARIZER), + + SendTo.CHAT => (Event.SEND_TO_CHAT, Path.CHAT), _ => (Event.NONE, Path.ASSISTANTS), }; - - MessageBus.INSTANCE.DeferMessage(this, eventItem, contentToSend); + + switch (destination) + { + case SendTo.CHAT: + MessageBus.INSTANCE.DeferMessage(this, eventItem, this.ConvertToChatThread); + break; + + default: + MessageBus.INSTANCE.DeferMessage(this, eventItem, contentToSend); + break; + } + this.NavigationManager.NavigateTo(path); return Task.CompletedTask; } + + private async Task InnerResetForm() + { + this.resultingContentBlock = null; + this.providerSettings = default; + + await this.JsRuntime.ClearDiv(ASSISTANT_RESULT_DIV_ID); + await this.JsRuntime.ClearDiv(AFTER_RESULT_DIV_ID); + + this.ResetFrom(); + + this.inputIsValid = false; + this.inputIssues = []; + + this.form?.ResetValidation(); + this.StateHasChanged(); + this.form?.ResetValidation(); + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Blocks/Changelog.Logs.cs b/app/MindWork AI Studio/Components/Blocks/Changelog.Logs.cs index f23f86ab..472a68d1 100644 --- a/app/MindWork AI Studio/Components/Blocks/Changelog.Logs.cs +++ b/app/MindWork AI Studio/Components/Blocks/Changelog.Logs.cs @@ -13,6 +13,7 @@ public readonly record struct Log(int Build, string Display, string Filename) public static readonly Log[] LOGS = [ + new (172, "v0.8.10, build 172 (2024-08-18 19:44 UTC)", "v0.8.10.md"), new (171, "v0.8.9, build 171 (2024-08-18 10:35 UTC)", "v0.8.9.md"), new (170, "v0.8.8, build 170 (2024-08-14 06:30 UTC)", "v0.8.8.md"), new (169, "v0.8.7, build 169 (2024-08-01 19:08 UTC)", "v0.8.7.md"), diff --git a/app/MindWork AI Studio/Components/Pages/Agenda/AssistantAgenda.razor.cs b/app/MindWork AI Studio/Components/Pages/Agenda/AssistantAgenda.razor.cs index be056a69..8fc405a3 100644 --- a/app/MindWork AI Studio/Components/Pages/Agenda/AssistantAgenda.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/Agenda/AssistantAgenda.razor.cs @@ -1,5 +1,6 @@ using System.Text; +using AIStudio.Chat; using AIStudio.Tools; namespace AIStudio.Components.Pages.Agenda; @@ -97,9 +98,73 @@ the logistical challenges that come with an increasing number of participants. [ new SendToButton { - Self = SendToAssistant.AGENDA_ASSISTANT, + Self = SendTo.AGENDA_ASSISTANT, }, ]; + + protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + { + SystemPrompt = SystemPrompts.DEFAULT, + }; + + protected override void ResetFrom() + { + this.inputContent = string.Empty; + this.contentLines.Clear(); + this.selectedFoci = []; + this.justBriefly = []; + this.inputWhoIsPresenting = string.Empty; + if (!this.MightPreselectValues()) + { + this.inputTopic = string.Empty; + this.inputName = string.Empty; + this.inputDuration = string.Empty; + this.inputStartTime = string.Empty; + this.inputObjective = string.Empty; + this.inputModerator = string.Empty; + this.selectedTargetLanguage = CommonLanguages.AS_IS; + this.customTargetLanguage = string.Empty; + this.introduceParticipants = false; + this.isMeetingVirtual = true; + this.inputLocation = string.Empty; + this.goingToDinner = false; + this.doingSocialActivity = false; + this.needToArriveAndDepart = false; + this.durationLunchBreak = 0; + this.durationBreaks = 0; + this.activeParticipation = false; + this.numberParticipants = NumberParticipants.NOT_SPECIFIED; + } + } + + protected override bool MightPreselectValues() + { + if (this.SettingsManager.ConfigurationData.Agenda.PreselectOptions) + { + this.inputTopic = this.SettingsManager.ConfigurationData.Agenda.PreselectTopic; + this.inputName = this.SettingsManager.ConfigurationData.Agenda.PreselectName; + this.inputDuration = this.SettingsManager.ConfigurationData.Agenda.PreselectDuration; + this.inputStartTime = this.SettingsManager.ConfigurationData.Agenda.PreselectStartTime; + this.inputObjective = this.SettingsManager.ConfigurationData.Agenda.PreselectObjective; + this.inputModerator = this.SettingsManager.ConfigurationData.Agenda.PreselectModerator; + this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.Agenda.PreselectedTargetLanguage; + this.customTargetLanguage = this.SettingsManager.ConfigurationData.Agenda.PreselectedOtherLanguage; + this.introduceParticipants = this.SettingsManager.ConfigurationData.Agenda.PreselectIntroduceParticipants; + this.isMeetingVirtual = this.SettingsManager.ConfigurationData.Agenda.PreselectIsMeetingVirtual; + this.inputLocation = this.SettingsManager.ConfigurationData.Agenda.PreselectLocation; + this.goingToDinner = this.SettingsManager.ConfigurationData.Agenda.PreselectJointDinner; + this.doingSocialActivity = this.SettingsManager.ConfigurationData.Agenda.PreselectSocialActivity; + this.needToArriveAndDepart = this.SettingsManager.ConfigurationData.Agenda.PreselectArriveAndDepart; + this.durationLunchBreak = this.SettingsManager.ConfigurationData.Agenda.PreselectLunchTime; + this.durationBreaks = this.SettingsManager.ConfigurationData.Agenda.PreselectBreakTime; + this.activeParticipation = this.SettingsManager.ConfigurationData.Agenda.PreselectActiveParticipation; + this.numberParticipants = this.SettingsManager.ConfigurationData.Agenda.PreselectNumberParticipants; + this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Agenda.PreselectedProvider); + return true; + } + + return false; + } private string inputTopic = string.Empty; private string inputName = string.Empty; @@ -130,29 +195,7 @@ the logistical challenges that come with an increasing number of participants. protected override async Task OnInitializedAsync() { - if (this.SettingsManager.ConfigurationData.Agenda.PreselectOptions) - { - this.inputTopic = this.SettingsManager.ConfigurationData.Agenda.PreselectTopic; - this.inputName = this.SettingsManager.ConfigurationData.Agenda.PreselectName; - this.inputDuration = this.SettingsManager.ConfigurationData.Agenda.PreselectDuration; - this.inputStartTime = this.SettingsManager.ConfigurationData.Agenda.PreselectStartTime; - this.inputObjective = this.SettingsManager.ConfigurationData.Agenda.PreselectObjective; - this.inputModerator = this.SettingsManager.ConfigurationData.Agenda.PreselectModerator; - this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.Agenda.PreselectedTargetLanguage; - this.customTargetLanguage = this.SettingsManager.ConfigurationData.Agenda.PreselectedOtherLanguage; - this.introduceParticipants = this.SettingsManager.ConfigurationData.Agenda.PreselectIntroduceParticipants; - this.isMeetingVirtual = this.SettingsManager.ConfigurationData.Agenda.PreselectIsMeetingVirtual; - this.inputLocation = this.SettingsManager.ConfigurationData.Agenda.PreselectLocation; - this.goingToDinner = this.SettingsManager.ConfigurationData.Agenda.PreselectJointDinner; - this.doingSocialActivity = this.SettingsManager.ConfigurationData.Agenda.PreselectSocialActivity; - this.needToArriveAndDepart = this.SettingsManager.ConfigurationData.Agenda.PreselectArriveAndDepart; - this.durationLunchBreak = this.SettingsManager.ConfigurationData.Agenda.PreselectLunchTime; - this.durationBreaks = this.SettingsManager.ConfigurationData.Agenda.PreselectBreakTime; - this.activeParticipation = this.SettingsManager.ConfigurationData.Agenda.PreselectActiveParticipation; - this.numberParticipants = this.SettingsManager.ConfigurationData.Agenda.PreselectNumberParticipants; - this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Agenda.PreselectedProvider); - } - + this.MightPreselectValues(); var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages(Event.SEND_TO_AGENDA_ASSISTANT).FirstOrDefault(); if (deferredContent is not null) this.inputContent = deferredContent; diff --git a/app/MindWork AI Studio/Components/Pages/Chat.razor.cs b/app/MindWork AI Studio/Components/Pages/Chat.razor.cs index c52c4af6..7cf84d9c 100644 --- a/app/MindWork AI Studio/Components/Pages/Chat.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/Chat.razor.cs @@ -62,6 +62,24 @@ protected override async Task OnInitializedAsync() this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Chat.PreselectedProvider); } + var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages(Event.SEND_TO_CHAT).FirstOrDefault(); + if (deferredContent is not null) + { + this.chatThread = deferredContent; + if (this.chatThread is not null) + { + var firstUserBlock = this.chatThread.Blocks.FirstOrDefault(x => x.Role == ChatRole.USER); + if (firstUserBlock is not null) + { + this.chatThread.Name = firstUserBlock.Content switch + { + ContentText textBlock => this.ExtractThreadName(textBlock.Text), + _ => "Thread" + }; + } + } + } + await base.OnInitializedAsync(); } @@ -93,7 +111,7 @@ private async Task SendMessage() ChatId = Guid.NewGuid(), Name = threadName, Seed = this.RNG.Next(), - SystemPrompt = "You are a helpful assistant!", + SystemPrompt = SystemPrompts.DEFAULT, Blocks = [], }; } diff --git a/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor.cs b/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor.cs index ac6a2c1d..8b577fee 100644 --- a/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/Coding/AssistantCoding.razor.cs @@ -30,10 +30,33 @@ messages. You can also help with code refactoring and optimization. [ new SendToButton { - Self = SendToAssistant.CODING_ASSISTANT, + Self = SendTo.CODING_ASSISTANT, }, ]; + protected override void ResetFrom() + { + this.codingContexts.Clear(); + this.compilerMessages = string.Empty; + this.questions = string.Empty; + if (!this.MightPreselectValues()) + { + this.provideCompilerMessages = false; + } + } + + protected override bool MightPreselectValues() + { + if (this.SettingsManager.ConfigurationData.Coding.PreselectOptions) + { + this.provideCompilerMessages = this.SettingsManager.ConfigurationData.Coding.PreselectCompilerMessages; + this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Coding.PreselectedProvider); + return true; + } + + return false; + } + private readonly List codingContexts = new(); private bool provideCompilerMessages; private string compilerMessages = string.Empty; @@ -43,12 +66,7 @@ messages. You can also help with code refactoring and optimization. protected override async Task OnInitializedAsync() { - if (this.SettingsManager.ConfigurationData.Coding.PreselectOptions) - { - this.provideCompilerMessages = this.SettingsManager.ConfigurationData.Coding.PreselectCompilerMessages; - this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Coding.PreselectedProvider); - } - + this.MightPreselectValues(); var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages(Event.SEND_TO_CODING_ASSISTANT).FirstOrDefault(); if (deferredContent is not null) this.questions = deferredContent; @@ -101,9 +119,13 @@ private async Task GetSupport() foreach (var codingContext in this.codingContexts) { sbContext.AppendLine($"ID: {codingContext.Id}"); - sbContext.AppendLine($"Language: {codingContext.Language.Name()}"); - sbContext.AppendLine($"Other Language: {codingContext.OtherLanguage}"); - sbContext.AppendLine($"Content:"); + + if(codingContext.Language is not CommonCodingLanguages.OTHER) + sbContext.AppendLine($"Language: {codingContext.Language.Name()}"); + else + sbContext.AppendLine($"Language: {codingContext.OtherLanguage}"); + + sbContext.AppendLine("Content:"); sbContext.AppendLine("```"); sbContext.AppendLine(codingContext.Code); sbContext.AppendLine("```"); diff --git a/app/MindWork AI Studio/Components/Pages/GrammarSpelling/AssistantGrammarSpelling.razor.cs b/app/MindWork AI Studio/Components/Pages/GrammarSpelling/AssistantGrammarSpelling.razor.cs index 3d7916c2..eef9cd51 100644 --- a/app/MindWork AI Studio/Components/Pages/GrammarSpelling/AssistantGrammarSpelling.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/GrammarSpelling/AssistantGrammarSpelling.razor.cs @@ -1,3 +1,4 @@ +using AIStudio.Chat; using AIStudio.Tools; namespace AIStudio.Components.Pages.GrammarSpelling; @@ -30,23 +31,46 @@ Germany and German in Austria differ. You receive text as input. You check the s new ButtonData("Copy result", Icons.Material.Filled.ContentCopy, Color.Default, string.Empty, () => this.CopyToClipboard(this.correctedText)), new SendToButton { - Self = SendToAssistant.GRAMMAR_SPELLING_ASSISTANT, + Self = SendTo.GRAMMAR_SPELLING_ASSISTANT, UseResultingContentBlockData = false, - GetData = () => string.IsNullOrWhiteSpace(this.correctedText) ? this.inputText : this.correctedText + GetText = () => string.IsNullOrWhiteSpace(this.correctedText) ? this.inputText : this.correctedText }, ]; + + protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + { + SystemPrompt = SystemPrompts.DEFAULT, + }; + + protected override void ResetFrom() + { + this.inputText = string.Empty; + this.correctedText = string.Empty; + if (!this.MightPreselectValues()) + { + this.selectedTargetLanguage = CommonLanguages.AS_IS; + this.customTargetLanguage = string.Empty; + } + } - #region Overrides of ComponentBase - - protected override async Task OnInitializedAsync() + protected override bool MightPreselectValues() { if (this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectOptions) { this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedTargetLanguage; this.customTargetLanguage = this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedOtherLanguage; this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.GrammarSpelling.PreselectedProvider); + return true; } + return false; + } + + #region Overrides of ComponentBase + + protected override async Task OnInitializedAsync() + { + this.MightPreselectValues(); var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages(Event.SEND_TO_GRAMMAR_SPELLING_ASSISTANT).FirstOrDefault(); if (deferredContent is not null) this.inputText = deferredContent; diff --git a/app/MindWork AI Studio/Components/Pages/IconFinder/AssistantIconFinder.razor.cs b/app/MindWork AI Studio/Components/Pages/IconFinder/AssistantIconFinder.razor.cs index 72547580..2b987241 100644 --- a/app/MindWork AI Studio/Components/Pages/IconFinder/AssistantIconFinder.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/IconFinder/AssistantIconFinder.razor.cs @@ -32,20 +32,36 @@ quotation marks. [ new SendToButton { - Self = SendToAssistant.ICON_FINDER_ASSISTANT, + Self = SendTo.ICON_FINDER_ASSISTANT, }, ]; - #region Overrides of ComponentBase + protected override void ResetFrom() + { + this.inputContext = string.Empty; + if (!this.MightPreselectValues()) + { + this.selectedIconSource = IconSources.GENERIC; + } + } - protected override async Task OnInitializedAsync() + protected override bool MightPreselectValues() { if (this.SettingsManager.ConfigurationData.IconFinder.PreselectOptions) { this.selectedIconSource = this.SettingsManager.ConfigurationData.IconFinder.PreselectedSource; this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.IconFinder.PreselectedProvider); + return true; } + + return false; + } + + #region Overrides of ComponentBase + protected override async Task OnInitializedAsync() + { + this.MightPreselectValues(); var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages(Event.SEND_TO_ICON_FINDER_ASSISTANT).FirstOrDefault(); if (deferredContent is not null) this.inputContext = deferredContent; diff --git a/app/MindWork AI Studio/Components/Pages/RewriteImprove/AssistantRewriteImprove.razor.cs b/app/MindWork AI Studio/Components/Pages/RewriteImprove/AssistantRewriteImprove.razor.cs index c2feff8c..ce60f257 100644 --- a/app/MindWork AI Studio/Components/Pages/RewriteImprove/AssistantRewriteImprove.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/RewriteImprove/AssistantRewriteImprove.razor.cs @@ -1,3 +1,4 @@ +using AIStudio.Chat; using AIStudio.Tools; namespace AIStudio.Components.Pages.RewriteImprove; @@ -31,15 +32,30 @@ text. You can also correct spelling and grammar issues. You never add additional new ButtonData("Copy result", Icons.Material.Filled.ContentCopy, Color.Default, string.Empty, () => this.CopyToClipboard(this.rewrittenText)), new SendToButton { - Self = SendToAssistant.REWRITE_ASSISTANT, + Self = SendTo.REWRITE_ASSISTANT, UseResultingContentBlockData = false, - GetData = () => string.IsNullOrWhiteSpace(this.rewrittenText) ? this.inputText : this.rewrittenText, + GetText = () => string.IsNullOrWhiteSpace(this.rewrittenText) ? this.inputText : this.rewrittenText, }, ]; + + protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + { + SystemPrompt = SystemPrompts.DEFAULT, + }; - #region Overrides of ComponentBase - - protected override async Task OnInitializedAsync() + protected override void ResetFrom() + { + this.inputText = string.Empty; + this.rewrittenText = string.Empty; + if (!this.MightPreselectValues()) + { + this.selectedTargetLanguage = CommonLanguages.AS_IS; + this.customTargetLanguage = string.Empty; + this.selectedWritingStyle = WritingStyles.NOT_SPECIFIED; + } + } + + protected override bool MightPreselectValues() { if (this.SettingsManager.ConfigurationData.RewriteImprove.PreselectOptions) { @@ -47,8 +63,17 @@ protected override async Task OnInitializedAsync() this.customTargetLanguage = this.SettingsManager.ConfigurationData.RewriteImprove.PreselectedOtherLanguage; this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.RewriteImprove.PreselectedProvider); this.selectedWritingStyle = this.SettingsManager.ConfigurationData.RewriteImprove.PreselectedWritingStyle; + return true; } + return false; + } + + #region Overrides of ComponentBase + + protected override async Task OnInitializedAsync() + { + this.MightPreselectValues(); var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages(Event.SEND_TO_REWRITE_ASSISTANT).FirstOrDefault(); if (deferredContent is not null) this.inputText = deferredContent; diff --git a/app/MindWork AI Studio/Components/Pages/SendToAssistant.cs b/app/MindWork AI Studio/Components/Pages/SendTo.cs similarity index 87% rename from app/MindWork AI Studio/Components/Pages/SendToAssistant.cs rename to app/MindWork AI Studio/Components/Pages/SendTo.cs index 4a12621b..86946673 100644 --- a/app/MindWork AI Studio/Components/Pages/SendToAssistant.cs +++ b/app/MindWork AI Studio/Components/Pages/SendTo.cs @@ -1,6 +1,6 @@ namespace AIStudio.Components.Pages; -public enum SendToAssistant +public enum SendTo { NONE = 0, @@ -11,4 +11,6 @@ public enum SendToAssistant AGENDA_ASSISTANT, CODING_ASSISTANT, TEXT_SUMMARIZER_ASSISTANT, + + CHAT, } \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/SendToAssistantExtensions.cs b/app/MindWork AI Studio/Components/Pages/SendToAssistantExtensions.cs deleted file mode 100644 index cbb4748f..00000000 --- a/app/MindWork AI Studio/Components/Pages/SendToAssistantExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace AIStudio.Components.Pages; - -public static class SendToAssistantExtensions -{ - public static string Name(this SendToAssistant assistant) - { - return assistant switch - { - SendToAssistant.GRAMMAR_SPELLING_ASSISTANT => "Grammar & Spelling Assistant", - SendToAssistant.TEXT_SUMMARIZER_ASSISTANT => "Text Summarizer Assistant", - SendToAssistant.ICON_FINDER_ASSISTANT => "Icon Finder Assistant", - SendToAssistant.TRANSLATION_ASSISTANT => "Translation Assistant", - SendToAssistant.REWRITE_ASSISTANT => "Rewrite Assistant", - SendToAssistant.AGENDA_ASSISTANT => "Agenda Assistant", - SendToAssistant.CODING_ASSISTANT => "Coding Assistant", - - _ => "Send to ...", - }; - } -} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/SendToExtensions.cs b/app/MindWork AI Studio/Components/Pages/SendToExtensions.cs new file mode 100644 index 00000000..49699aa0 --- /dev/null +++ b/app/MindWork AI Studio/Components/Pages/SendToExtensions.cs @@ -0,0 +1,22 @@ +namespace AIStudio.Components.Pages; + +public static class SendToExtensions +{ + public static string Name(this SendTo assistant) + { + return assistant switch + { + SendTo.GRAMMAR_SPELLING_ASSISTANT => "Grammar & Spelling Assistant", + SendTo.TEXT_SUMMARIZER_ASSISTANT => "Text Summarizer Assistant", + SendTo.ICON_FINDER_ASSISTANT => "Icon Finder Assistant", + SendTo.TRANSLATION_ASSISTANT => "Translation Assistant", + SendTo.REWRITE_ASSISTANT => "Rewrite Assistant", + SendTo.AGENDA_ASSISTANT => "Agenda Assistant", + SendTo.CODING_ASSISTANT => "Coding Assistant", + + SendTo.CHAT => "New Chat", + + _ => "Send to ...", + }; + } +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Components/Pages/TextSummarizer/AssistantTextSummarizer.razor.cs b/app/MindWork AI Studio/Components/Pages/TextSummarizer/AssistantTextSummarizer.razor.cs index 696cffb0..41936acf 100644 --- a/app/MindWork AI Studio/Components/Pages/TextSummarizer/AssistantTextSummarizer.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/TextSummarizer/AssistantTextSummarizer.razor.cs @@ -1,3 +1,4 @@ +using AIStudio.Chat; using AIStudio.Tools; namespace AIStudio.Components.Pages.TextSummarizer; @@ -27,10 +28,42 @@ You get a long text as input. The user wants to get a summary of the text. [ new SendToButton { - Self = SendToAssistant.TEXT_SUMMARIZER_ASSISTANT, + Self = SendTo.TEXT_SUMMARIZER_ASSISTANT, }, ]; + protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + { + SystemPrompt = SystemPrompts.DEFAULT, + }; + + protected override void ResetFrom() + { + this.inputText = string.Empty; + if(!this.MightPreselectValues()) + { + this.selectedTargetLanguage = CommonLanguages.AS_IS; + this.customTargetLanguage = string.Empty; + this.selectedComplexity = Complexity.NO_CHANGE; + this.expertInField = string.Empty; + } + } + + protected override bool MightPreselectValues() + { + if (this.SettingsManager.ConfigurationData.TextSummarizer.PreselectOptions) + { + this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedTargetLanguage; + this.customTargetLanguage = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedOtherLanguage; + this.selectedComplexity = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedComplexity; + this.expertInField = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedExpertInField; + this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedProvider); + return true; + } + + return false; + } + private string inputText = string.Empty; private bool isAgentRunning; private CommonLanguages selectedTargetLanguage; @@ -42,15 +75,7 @@ You get a long text as input. The user wants to get a summary of the text. protected override async Task OnInitializedAsync() { - if(this.SettingsManager.ConfigurationData.TextSummarizer.PreselectOptions) - { - this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedTargetLanguage; - this.customTargetLanguage = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedOtherLanguage; - this.selectedComplexity = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedComplexity; - this.expertInField = this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedExpertInField; - this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.TextSummarizer.PreselectedProvider); - } - + this.MightPreselectValues(); var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages(Event.SEND_TO_TEXT_SUMMARIZER_ASSISTANT).FirstOrDefault(); if (deferredContent is not null) this.inputText = deferredContent; diff --git a/app/MindWork AI Studio/Components/Pages/Translation/AssistantTranslation.razor.cs b/app/MindWork AI Studio/Components/Pages/Translation/AssistantTranslation.razor.cs index 0b12e43b..e718e88f 100644 --- a/app/MindWork AI Studio/Components/Pages/Translation/AssistantTranslation.razor.cs +++ b/app/MindWork AI Studio/Components/Pages/Translation/AssistantTranslation.razor.cs @@ -1,3 +1,4 @@ +using AIStudio.Chat; using AIStudio.Tools; namespace AIStudio.Components.Pages.Translation; @@ -23,10 +24,41 @@ Provide the translation in the requested language. Do not add any information. C [ new SendToButton { - Self = SendToAssistant.TRANSLATION_ASSISTANT, + Self = SendTo.TRANSLATION_ASSISTANT, }, ]; + protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + { + SystemPrompt = SystemPrompts.DEFAULT, + }; + + protected override void ResetFrom() + { + this.inputText = string.Empty; + this.inputTextLastTranslation = string.Empty; + if (!this.MightPreselectValues()) + { + this.liveTranslation = false; + this.selectedTargetLanguage = CommonLanguages.AS_IS; + this.customTargetLanguage = string.Empty; + } + } + + protected override bool MightPreselectValues() + { + if (this.SettingsManager.ConfigurationData.Translation.PreselectOptions) + { + this.liveTranslation = this.SettingsManager.ConfigurationData.Translation.PreselectLiveTranslation; + this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.Translation.PreselectedTargetLanguage; + this.customTargetLanguage = this.SettingsManager.ConfigurationData.Translation.PreselectOtherLanguage; + this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Translation.PreselectedProvider); + return true; + } + + return false; + } + private bool liveTranslation; private bool isAgentRunning; private string inputText = string.Empty; @@ -38,14 +70,7 @@ Provide the translation in the requested language. Do not add any information. C protected override async Task OnInitializedAsync() { - if (this.SettingsManager.ConfigurationData.Translation.PreselectOptions) - { - this.liveTranslation = this.SettingsManager.ConfigurationData.Translation.PreselectLiveTranslation; - this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.Translation.PreselectedTargetLanguage; - this.customTargetLanguage = this.SettingsManager.ConfigurationData.Translation.PreselectOtherLanguage; - this.providerSettings = this.SettingsManager.ConfigurationData.Providers.FirstOrDefault(x => x.Id == this.SettingsManager.ConfigurationData.Translation.PreselectedProvider); - } - + this.MightPreselectValues(); var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages(Event.SEND_TO_TRANSLATION_ASSISTANT).FirstOrDefault(); if (deferredContent is not null) this.inputText = deferredContent; diff --git a/app/MindWork AI Studio/Tools/Event.cs b/app/MindWork AI Studio/Tools/Event.cs index 84e780f5..8103e182 100644 --- a/app/MindWork AI Studio/Tools/Event.cs +++ b/app/MindWork AI Studio/Tools/Event.cs @@ -16,7 +16,7 @@ public enum Event HAS_CHAT_UNSAVED_CHANGES, RESET_CHAT_STATE, - // Send assistant events: + // Send events: SEND_TO_GRAMMAR_SPELLING_ASSISTANT, SEND_TO_ICON_FINDER_ASSISTANT, SEND_TO_REWRITE_ASSISTANT, @@ -24,4 +24,5 @@ public enum Event SEND_TO_AGENDA_ASSISTANT, SEND_TO_CODING_ASSISTANT, SEND_TO_TEXT_SUMMARIZER_ASSISTANT, + SEND_TO_CHAT, } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/JsRuntimeExtensions.cs b/app/MindWork AI Studio/Tools/JsRuntimeExtensions.cs index d8132346..7264fc0e 100644 --- a/app/MindWork AI Studio/Tools/JsRuntimeExtensions.cs +++ b/app/MindWork AI Studio/Tools/JsRuntimeExtensions.cs @@ -8,4 +8,9 @@ public static async Task GenerateAndShowDiff(this IJSRuntime jsRuntime, string t { await jsRuntime.InvokeVoidAsync("generateDiff", text1, text2, AssistantBase.ASSISTANT_RESULT_DIV_ID, AssistantBase.AFTER_RESULT_DIV_ID); } + + public static async Task ClearDiv(this IJSRuntime jsRuntime, string divId) + { + await jsRuntime.InvokeVoidAsync("clearDiv", divId); + } } \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/SendToButton.cs b/app/MindWork AI Studio/Tools/SendToButton.cs index 4baad16b..2bce3ce0 100644 --- a/app/MindWork AI Studio/Tools/SendToButton.cs +++ b/app/MindWork AI Studio/Tools/SendToButton.cs @@ -6,10 +6,10 @@ public readonly record struct SendToButton() : IButtonData { public ButtonTypes Type => ButtonTypes.SEND_TO; - public Func GetData { get; init; } = () => string.Empty; + public Func GetText { get; init; } = () => string.Empty; public bool UseResultingContentBlockData { get; init; } = true; - public SendToAssistant Self { get; init; } = SendToAssistant.NONE; + public SendTo Self { get; init; } = SendTo.NONE; } \ No newline at end of file diff --git a/app/MindWork AI Studio/packages.lock.json b/app/MindWork AI Studio/packages.lock.json index 7cad8d7d..c19fb674 100644 --- a/app/MindWork AI Studio/packages.lock.json +++ b/app/MindWork AI Studio/packages.lock.json @@ -178,6 +178,6 @@ "contentHash": "FHNOatmUq0sqJOkTx+UF/9YK1f180cnW5FVqnQMvYUN0elp6wFzbtPSiqbo1/ru8ICp43JM1i7kKkk6GsNGHlA==" } }, - "net8.0/osx-x64": {} + "net8.0/osx-arm64": {} } } \ No newline at end of file diff --git a/app/MindWork AI Studio/wwwroot/app.js b/app/MindWork AI Studio/wwwroot/app.js index 6629610d..61a52418 100644 --- a/app/MindWork AI Studio/wwwroot/app.js +++ b/app/MindWork AI Studio/wwwroot/app.js @@ -16,4 +16,9 @@ window.generateDiff = function (text1, text2, divDiff, divLegend) { `; +} + +window.clearDiv = function (divName) { + let targetDiv = document.getElementById(divName); + targetDiv.innerHTML = ''; } \ No newline at end of file diff --git a/app/MindWork AI Studio/wwwroot/changelog/v0.8.10.md b/app/MindWork AI Studio/wwwroot/changelog/v0.8.10.md new file mode 100644 index 00000000..8eff67ae --- /dev/null +++ b/app/MindWork AI Studio/wwwroot/changelog/v0.8.10.md @@ -0,0 +1,4 @@ +# v0.8.10, build 172 (2024-08-18 19:44 UTC) +- Added the possibility to send any assistant context to a new chat session for further questions +- Added a reset button to all assistants to clear the current context +- Improved the coding assistant's language handling when creating the corresponding prompt \ No newline at end of file diff --git a/metadata.txt b/metadata.txt index c8bcd12a..5d7a080f 100644 --- a/metadata.txt +++ b/metadata.txt @@ -1,9 +1,9 @@ -0.8.9 -2024-08-18 10:35:05 UTC -171 +0.8.10 +2024-08-18 19:44:06 UTC +172 8.0.108 (commit 665a05cea7) 8.0.8 (commit 08338fcaa5) 1.80.1 (commit 3f5fd8dd4) 7.6.0 1.7.1 -909fbe89bbb, release +9a928d41e15, release diff --git a/runtime/Cargo.lock b/runtime/Cargo.lock index 0a4c0a53..9cf3c3ab 100644 --- a/runtime/Cargo.lock +++ b/runtime/Cargo.lock @@ -2308,7 +2308,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mindwork-ai-studio" -version = "0.8.9" +version = "0.8.10" dependencies = [ "arboard", "flexi_logger", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 36694aac..f00ce0a5 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindwork-ai-studio" -version = "0.8.9" +version = "0.8.10" edition = "2021" description = "MindWork AI Studio" authors = ["Thorsten Sommer"] diff --git a/runtime/tauri.conf.json b/runtime/tauri.conf.json index 7ff86aca..400292ae 100644 --- a/runtime/tauri.conf.json +++ b/runtime/tauri.conf.json @@ -6,7 +6,7 @@ }, "package": { "productName": "MindWork AI Studio", - "version": "0.8.9" + "version": "0.8.10" }, "tauri": { "allowlist": {