mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-13 11:14:14 +00:00
Refactored user prompt handling in assistants when sending to chat
This commit is contained in:
parent
79da608ae2
commit
5332001627
@ -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<SettingsDialogAgenda>
|
||||
|
||||
protected override Func<Task> 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()
|
||||
{
|
||||
|
||||
@ -79,10 +79,29 @@ public abstract partial class AssistantBase<TSettings> : 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;
|
||||
|
||||
@ -339,6 +358,47 @@ public abstract partial class AssistantBase<TSettings> : 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)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(icon))
|
||||
|
||||
@ -29,6 +29,10 @@ public partial class AssistantCoding : AssistantBaseCore<SettingsDialogCoding>
|
||||
|
||||
protected override Func<Task> 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();
|
||||
|
||||
@ -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<SettingsDialogWritingEMa
|
||||
|
||||
protected override Func<Task> 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()
|
||||
{
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.GrammarSpelling;
|
||||
@ -41,10 +40,9 @@ public partial class AssistantGrammarSpelling : AssistantBaseCore<SettingsDialog
|
||||
|
||||
protected override Func<Task> 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()
|
||||
{
|
||||
|
||||
@ -27,6 +27,13 @@ public partial class AssistantIconFinder : AssistantBaseCore<SettingsDialogIconF
|
||||
|
||||
protected override Func<Task> 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;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.JobPosting;
|
||||
@ -51,10 +50,34 @@ public partial class AssistantJobPostings : AssistantBaseCore<SettingsDialogJobP
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.LegalCheck;
|
||||
@ -28,10 +27,9 @@ public partial class AssistantLegalCheck : AssistantBaseCore<SettingsDialogLegal
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
@ -42,10 +42,9 @@ public partial class AssistantRewriteImprove : AssistantBaseCore<SettingsDialogR
|
||||
|
||||
protected override Func<Task> 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()
|
||||
{
|
||||
|
||||
@ -53,10 +53,29 @@ public partial class AssistantSynonyms : AssistantBaseCore<SettingsDialogSynonym
|
||||
|
||||
protected override Func<Task> 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()
|
||||
{
|
||||
|
||||
@ -36,10 +36,12 @@ public partial class AssistantTranslation : AssistantBaseCore<SettingsDialogTran
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user