diff --git a/app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor.cs b/app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor.cs index 4658a16b..6f6261f1 100644 --- a/app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor.cs +++ b/app/MindWork AI Studio/Assistants/Agenda/AssistantAgenda.razor.cs @@ -1,6 +1,5 @@ using System.Text; -using AIStudio.Chat; using AIStudio.Dialogs.Settings; namespace AIStudio.Assistants.Agenda; @@ -97,10 +96,12 @@ public partial class AssistantAgenda : AssistantBaseCore protected override Func SubmitAction => this.CreateAgenda; - protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with - { - SystemPrompt = SystemPrompts.DEFAULT, - }; + protected override string SendToChatVisibleUserPromptText => + $""" + {string.Format(T("Create an agenda for the meeting '{0}' with the following contents:"), this.inputName)} + + {this.inputContent} + """; protected override void ResetForm() { diff --git a/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs b/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs index c92d074e..332e25ba 100644 --- a/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs +++ b/app/MindWork AI Studio/Assistants/AssistantBase.razor.cs @@ -79,10 +79,29 @@ public abstract partial class AssistantBase : AssistantLowerBase wher protected virtual bool ShowReset => true; - protected virtual ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + protected virtual string? SendToChatVisibleUserPromptPrefix => null; + + protected virtual string? SendToChatVisibleUserPromptContent => null; + + protected virtual string? SendToChatVisibleUserPromptText { - SystemPrompt = SystemPrompts.DEFAULT, - }; + get + { + if (string.IsNullOrWhiteSpace(this.SendToChatVisibleUserPromptPrefix)) + return null; + + if (string.IsNullOrWhiteSpace(this.SendToChatVisibleUserPromptContent)) + return this.SendToChatVisibleUserPromptPrefix; + + return $""" + {this.SendToChatVisibleUserPromptPrefix} + + {this.SendToChatVisibleUserPromptContent} + """; + } + } + + protected virtual ChatThread ConvertToChatThread => this.CreateSendToChatThread(); private protected virtual RenderFragment? HeaderActions => null; @@ -338,6 +357,47 @@ public abstract partial class AssistantBase : AssistantLowerBase wher { await this.RustService.CopyText2Clipboard(this.Snackbar, this.Result2Copy()); } + + private ChatThread CreateSendToChatThread() + { + var originalChatThread = this.chatThread ?? new ChatThread(); + if (string.IsNullOrWhiteSpace(this.SendToChatVisibleUserPromptText)) + return originalChatThread with + { + SystemPrompt = SystemPrompts.DEFAULT, + }; + + var earliestBlock = originalChatThread.Blocks.MinBy(x => x.Time); + var visiblePromptTime = earliestBlock is null + ? DateTimeOffset.Now + : earliestBlock.Time == DateTimeOffset.MinValue + ? earliestBlock.Time + : earliestBlock.Time.AddTicks(-1); + + var transferredBlocks = originalChatThread.Blocks + .Select(block => block.Role is ChatRole.USER + ? block.DeepClone(changeHideState: true) + : block.DeepClone()) + .ToList(); + + transferredBlocks.Insert(0, new ContentBlock + { + Time = visiblePromptTime, + ContentType = ContentType.TEXT, + HideFromUser = false, + Role = ChatRole.USER, + Content = new ContentText + { + Text = this.SendToChatVisibleUserPromptText, + }, + }); + + return originalChatThread with + { + SystemPrompt = SystemPrompts.DEFAULT, + Blocks = transferredBlocks, + }; + } private static string? GetButtonIcon(string icon) { diff --git a/app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor.cs b/app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor.cs index c96043ab..b96be950 100644 --- a/app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor.cs +++ b/app/MindWork AI Studio/Assistants/Coding/AssistantCoding.razor.cs @@ -29,6 +29,10 @@ public partial class AssistantCoding : AssistantBaseCore protected override Func SubmitAction => this.GetSupport; + protected override string SendToChatVisibleUserPromptPrefix => T("Help me with the following coding question:"); + + protected override string SendToChatVisibleUserPromptContent => this.questions; + protected override void ResetForm() { this.codingContexts.Clear(); diff --git a/app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor.cs b/app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor.cs index 70baa91e..a2ec29de 100644 --- a/app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor.cs +++ b/app/MindWork AI Studio/Assistants/EMail/AssistantEMail.razor.cs @@ -1,6 +1,5 @@ using System.Text; -using AIStudio.Chat; using AIStudio.Dialogs.Settings; namespace AIStudio.Assistants.EMail; @@ -26,10 +25,9 @@ public partial class AssistantEMail : AssistantBaseCore SubmitAction => this.CreateMail; - protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with - { - SystemPrompt = SystemPrompts.DEFAULT, - }; + protected override string SendToChatVisibleUserPromptPrefix => T("Create an email based on the following bullet points:"); + + protected override string SendToChatVisibleUserPromptContent => this.inputBulletPoints; protected override void ResetForm() { diff --git a/app/MindWork AI Studio/Assistants/GrammarSpelling/AssistantGrammarSpelling.razor.cs b/app/MindWork AI Studio/Assistants/GrammarSpelling/AssistantGrammarSpelling.razor.cs index 64168fd2..b8dbbe12 100644 --- a/app/MindWork AI Studio/Assistants/GrammarSpelling/AssistantGrammarSpelling.razor.cs +++ b/app/MindWork AI Studio/Assistants/GrammarSpelling/AssistantGrammarSpelling.razor.cs @@ -1,4 +1,3 @@ -using AIStudio.Chat; using AIStudio.Dialogs.Settings; namespace AIStudio.Assistants.GrammarSpelling; @@ -41,10 +40,9 @@ public partial class AssistantGrammarSpelling : AssistantBaseCore SubmitAction => this.ProofreadText; - protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with - { - SystemPrompt = SystemPrompts.DEFAULT, - }; + protected override string SendToChatVisibleUserPromptPrefix => T("Check the following text for grammar and spelling mistakes:"); + + protected override string SendToChatVisibleUserPromptContent => this.inputText; protected override void ResetForm() { diff --git a/app/MindWork AI Studio/Assistants/IconFinder/AssistantIconFinder.razor.cs b/app/MindWork AI Studio/Assistants/IconFinder/AssistantIconFinder.razor.cs index 294cdd3a..ca86cb69 100644 --- a/app/MindWork AI Studio/Assistants/IconFinder/AssistantIconFinder.razor.cs +++ b/app/MindWork AI Studio/Assistants/IconFinder/AssistantIconFinder.razor.cs @@ -27,6 +27,13 @@ public partial class AssistantIconFinder : AssistantBaseCore SubmitAction => this.FindIcon; + protected override string SendToChatVisibleUserPromptText => + $""" + {string.Format(T("Find icon suggestions on {0} for the following context:"), this.selectedIconSource.Name())} + + {this.inputContext} + """; + protected override void ResetForm() { this.inputContext = string.Empty; diff --git a/app/MindWork AI Studio/Assistants/JobPosting/AssistantJobPostings.razor.cs b/app/MindWork AI Studio/Assistants/JobPosting/AssistantJobPostings.razor.cs index d13c2f6d..c13d05e6 100644 --- a/app/MindWork AI Studio/Assistants/JobPosting/AssistantJobPostings.razor.cs +++ b/app/MindWork AI Studio/Assistants/JobPosting/AssistantJobPostings.razor.cs @@ -1,4 +1,3 @@ -using AIStudio.Chat; using AIStudio.Dialogs.Settings; namespace AIStudio.Assistants.JobPosting; @@ -50,11 +49,35 @@ public partial class AssistantJobPostings : AssistantBaseCore false; protected override bool AllowProfiles => false; - - protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + + protected override string SendToChatVisibleUserPromptText { - SystemPrompt = SystemPrompts.DEFAULT, - }; + get + { + if (!string.IsNullOrWhiteSpace(this.inputCompanyName) && !string.IsNullOrWhiteSpace(this.inputJobDescription)) + { + return $""" + {string.Format(T("Create a job posting for {0} based on the following job description:"), this.inputCompanyName)} + + {this.inputJobDescription} + """; + } + + if (!string.IsNullOrWhiteSpace(this.inputCompanyName)) + return string.Format(T("Create a job posting for {0}."), this.inputCompanyName); + + if (!string.IsNullOrWhiteSpace(this.inputJobDescription)) + { + return $""" + {T("Create a job posting based on the following job description:")} + + {this.inputJobDescription} + """; + } + + return T("Create a job posting."); + } + } protected override void ResetForm() { diff --git a/app/MindWork AI Studio/Assistants/LegalCheck/AssistantLegalCheck.razor.cs b/app/MindWork AI Studio/Assistants/LegalCheck/AssistantLegalCheck.razor.cs index 100c3df4..e2120e6b 100644 --- a/app/MindWork AI Studio/Assistants/LegalCheck/AssistantLegalCheck.razor.cs +++ b/app/MindWork AI Studio/Assistants/LegalCheck/AssistantLegalCheck.razor.cs @@ -1,4 +1,3 @@ -using AIStudio.Chat; using AIStudio.Dialogs.Settings; namespace AIStudio.Assistants.LegalCheck; @@ -27,11 +26,10 @@ public partial class AssistantLegalCheck : AssistantBaseCore SubmitAction => this.AksQuestions; protected override bool SubmitDisabled => this.isAgentRunning; - - protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with - { - SystemPrompt = SystemPrompts.DEFAULT, - }; + + protected override string SendToChatVisibleUserPromptPrefix => T("Answer the following questions about a legal document:"); + + protected override string SendToChatVisibleUserPromptContent => this.inputQuestions; protected override void ResetForm() { diff --git a/app/MindWork AI Studio/Assistants/RewriteImprove/AssistantRewriteImprove.razor.cs b/app/MindWork AI Studio/Assistants/RewriteImprove/AssistantRewriteImprove.razor.cs index 2ddac0fd..2fe65408 100644 --- a/app/MindWork AI Studio/Assistants/RewriteImprove/AssistantRewriteImprove.razor.cs +++ b/app/MindWork AI Studio/Assistants/RewriteImprove/AssistantRewriteImprove.razor.cs @@ -42,10 +42,9 @@ public partial class AssistantRewriteImprove : AssistantBaseCore SubmitAction => this.RewriteText; - protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with - { - SystemPrompt = SystemPrompts.DEFAULT, - }; + protected override string SendToChatVisibleUserPromptPrefix => T("Rewrite and improve the following text:"); + + protected override string SendToChatVisibleUserPromptContent => this.inputText; protected override void ResetForm() { diff --git a/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor.cs b/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor.cs index 739a4a2f..f837e842 100644 --- a/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor.cs +++ b/app/MindWork AI Studio/Assistants/Synonym/AssistantSynonyms.razor.cs @@ -53,10 +53,29 @@ public partial class AssistantSynonyms : AssistantBaseCore SubmitAction => this.FindSynonyms; - protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with + protected override string SendToChatVisibleUserPromptText { - SystemPrompt = SystemPrompts.DEFAULT, - }; + get + { + if (string.IsNullOrWhiteSpace(this.inputContext)) + { + return $""" + {T("Find synonyms for the following word or phrase:")} + + {this.inputText} + """; + } + + return $""" + {T("Find synonyms for the following word or phrase:")} + + {this.inputText} + + {T("Context:")} + {this.inputContext} + """; + } + } protected override void ResetForm() { diff --git a/app/MindWork AI Studio/Assistants/Translation/AssistantTranslation.razor.cs b/app/MindWork AI Studio/Assistants/Translation/AssistantTranslation.razor.cs index 630e9249..84e18340 100644 --- a/app/MindWork AI Studio/Assistants/Translation/AssistantTranslation.razor.cs +++ b/app/MindWork AI Studio/Assistants/Translation/AssistantTranslation.razor.cs @@ -35,11 +35,13 @@ public partial class AssistantTranslation : AssistantBaseCore SubmitAction => () => this.TranslateText(true); protected override bool SubmitDisabled => this.isAgentRunning; - - protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with - { - SystemPrompt = SystemPrompts.DEFAULT, - }; + + protected override string SendToChatVisibleUserPromptText => + $""" + {string.Format(T("Translate the following text to {0}:"), this.selectedTargetLanguage is CommonLanguages.OTHER ? this.customTargetLanguage : this.selectedTargetLanguage.Name())} + + {this.inputText} + """; protected override void ResetForm() {