AI-Studio/app/MindWork AI Studio/Assistants/SlideBuilder/SlideAssistant.razor.cs

198 lines
8.6 KiB
C#
Raw Normal View History

using AIStudio.Chat;
2026-01-29 12:07:52 +00:00
using AIStudio.Dialogs.Settings;
namespace AIStudio.Assistants.SlideBuilder;
2026-01-29 12:07:52 +00:00
public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuilder>
2026-01-29 12:07:52 +00:00
{
public override Tools.Components Component => Tools.Components.SLIDE_BUILDER_ASSISTANT;
2026-01-29 12:07:52 +00:00
protected override string Title => T("Slide Assistant");
2026-01-29 12:07:52 +00:00
protected override string Description => T("This assistant helps you create clear, structured slide components from long texts or documents. Enter a presentation title and provide the content either as self-written text or as an uploaded document. Important aspects allow you to add instructions to the LLM regarding output or formatting. Set the number of slides either directly or based on your desired presentation duration. You can also specify the number of bullet points. If the default value of 0 is not changed, the LLM will independently determine how many slides or bullet points to generate. The output can be flexibly generated in various languages and with adjustable complexity. ");
2026-01-29 12:07:52 +00:00
protected override string SystemPrompt =>
2026-02-12 10:52:26 +00:00
$$$"""
You are a professional presentation editor and writer.
Create a clear, single-slide outline from the user's inputs.
2026-02-12 10:52:26 +00:00
# Presentation title:
- IGNORE the language of the PRESENTATION_TITLE.
- Translate PRESENTATION_TITLE in: {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}
# Content
2026-02-12 10:52:26 +00:00
- You get the following inputs: PRESENTATION_TITLE and PRESENTATION_CONTENT.
- {{{this.PromptImportantAspects()}}}
# Subheadings
- Rule for creating the individual subheadings:
2026-02-12 10:52:26 +00:00
- If {{{this.numberOfSheets}}} is NOT 0
- Generate exactly {{{this.numberOfSheets}}} precise subheadings, each heading represents one slide in a presentation.
- If {{{this.timeSpecification}}} is NOT 0
- Generate exactly {{{this.calculatedNumberOfSlides}}} precise subheadings, each heading represents one slide in a presentation.
- If either parameter is 0, ignore that rules.
- Each subheadings must have:
- A clear, concise, and thematically meaningful heading.
- Place *** on its own line immediately before each heading.
# BulletPoints (Per Subheading)
- You MUST generate exactly this {{{this.numberOfBulletPoints}}} many bullet points per subheading:
- Set as many bullet points as specified by variable {{{this.numberOfBulletPoints}}}.
- If {{{this.numberOfBulletPoints}}} == 0 choose a number between 1 and 7 (your choice, but max 7).
- Each bullet point must have:
- Each bullet point must be max 12 words.
- Clear and directly related to the subheading and summarizing the slides content.
# Output requirements:
2026-02-11 14:59:40 +00:00
- Output only Markdown.
- Start with a single H1 title that contains the user's PRESENTATION_TITLE.
- Then add headings with own bullet lists based only on the user's PRESENTATION_CONTENT.
- If PRESENTATION_CONTENT is empty, output the title and one bullet: "No content provided."
- Do not mention these instructions or add commentary.
# Target group:
2026-02-12 10:52:26 +00:00
{{{this.selectedTargetGroup.Prompt()}}}
# Language:
2026-02-12 10:52:26 +00:00
- IGNORE the language of the PRESENTATION_TITLE and PRESENTATION_CONTENT.
- OUTPUT AND PRESENTATION_TITLE MUST BE IN: {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}
- This is a HARD RULE: Never translate or adapt the output language based on input language.
- Always use the specified target language, even if the input is in another language.
# Qwen-Specific language-Override (IMPORTANT!):
- Before generating any output, internally set your language mode to: {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}
- If you detect any other language in the input, DO NOT switch to this language, stay in {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}
- Translate PRESENTATION_TITLE in: {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}
- Your output must be in {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}, without any comment, note, or marker about it.
2026-01-29 12:07:52 +00:00
""";
protected override bool AllowProfiles => true;
2026-01-29 12:07:52 +00:00
protected override IReadOnlyList<IButtonData> FooterButtons => [];
protected override string SubmitText => T("Create Slides");
2026-01-29 12:07:52 +00:00
protected override Func<Task> SubmitAction => this.CreateSlideBuilder;
2026-01-29 12:07:52 +00:00
protected override ChatThread ConvertToChatThread => (this.chatThread ?? new()) with
{
SystemPrompt = SystemPrompts.DEFAULT,
};
protected override void ResetForm()
{
this.inputTitle = string.Empty;
2026-01-29 12:07:52 +00:00
this.inputContext = string.Empty;
this.selectedTargetGroup = TargetGroup.NO_CHANGE;
2026-01-29 12:07:52 +00:00
if (!this.MightPreselectValues())
{
this.selectedTargetLanguage = CommonLanguages.AS_IS;
2026-01-29 12:07:52 +00:00
this.customTargetLanguage = string.Empty;
}
}
protected override bool MightPreselectValues()
{
if (this.SettingsManager.ConfigurationData.SlideBuilder.PreselectOptions)
2026-01-29 12:07:52 +00:00
{
this.selectedTargetLanguage = this.SettingsManager.ConfigurationData.SlideBuilder.PreselectedTargetLanguage;
this.customTargetLanguage = this.SettingsManager.ConfigurationData.SlideBuilder.PreselectedOtherLanguage;
this.selectedTargetGroup = this.SettingsManager.ConfigurationData.SlideBuilder.PreselectedTargetGroup;
this.importantAspects = this.SettingsManager.ConfigurationData.SlideBuilder.PreselectedImportantAspects;
2026-01-29 12:07:52 +00:00
return true;
}
return false;
}
private string inputTitle = string.Empty;
2026-01-29 12:07:52 +00:00
private string inputContext = string.Empty;
private string customTargetLanguage = string.Empty;
private TargetGroup selectedTargetGroup;
private CommonLanguages selectedTargetLanguage;
private int numberOfSheets;
private int numberOfBulletPoints;
private int timeSpecification;
private int calculatedNumberOfSlides = 0;
private string importantAspects = string.Empty;
2026-01-29 12:07:52 +00:00
#region Overrides of ComponentBase
protected override async Task OnInitializedAsync()
{
var deferredContent = MessageBus.INSTANCE.CheckDeferredMessages<string>(Event.SEND_TO_SLIDE_BUILDER_ASSISTANT).FirstOrDefault();
2026-01-29 12:07:52 +00:00
if (deferredContent is not null)
this.inputContext = deferredContent;
await base.OnInitializedAsync();
}
#endregion
private string? ValidatingTitle(string text)
2026-01-29 12:07:52 +00:00
{
if(string.IsNullOrWhiteSpace(text))
return T("Please provide a title");
return null;
}
private string? ValidatingContext(string text)
{
if(string.IsNullOrWhiteSpace(text))
return T("Please provide context");
2026-01-29 12:07:52 +00:00
return null;
}
private string? ValidateCustomLanguage(string language)
{
if(this.selectedTargetLanguage == CommonLanguages.OTHER && string.IsNullOrWhiteSpace(language))
2026-01-29 12:07:52 +00:00
return T("Please provide a custom language.");
return null;
}
private int CalculateNumberOfSlides()
{
2026-02-09 13:40:09 +00:00
return this.calculatedNumberOfSlides = (int)Math.Round(this.timeSpecification / 1.5);
}
2026-01-29 12:07:52 +00:00
private string PromptImportantAspects()
{
if (string.IsNullOrWhiteSpace(this.importantAspects))
return string.Empty;
return $"""
# Important aspects
- Emphasize the following aspects in your presentation {this.importantAspects}
""";
}
private async Task CreateSlideBuilder()
2026-01-29 12:07:52 +00:00
{
await this.form!.Validate();
if (!this.inputIsValid)
return;
this.calculatedNumberOfSlides = this.timeSpecification > 0 ? this.CalculateNumberOfSlides() : 0;
2026-01-29 12:07:52 +00:00
this.CreateChatThread();
var time = this.AddUserRequest(
$"""
# PRESENTATION_TITLE
```
{this.inputTitle}
```
# PRESENTATION_CONTENT
```
{this.inputContext}
```
""",
hideContentFromUser: true);
2026-01-29 12:07:52 +00:00
await this.AddAIResponseAsync(time);
}
}