Add AttachDocuments option in SlideAssistant

This commit is contained in:
hart_s3 2026-02-25 14:52:21 +01:00
parent 7f5efc8044
commit ec23b0c342
3 changed files with 90 additions and 7 deletions

View File

@ -1342,6 +1342,9 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T1790167032
-- Slide Assistant
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T1883918574"] = "Slide Assistant"
-- Please provide some input
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T2236278390"] = "Please provide some input"
-- Target language
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T237828418"] = "Target language"
@ -1354,6 +1357,9 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T2709966651
-- Please provide a title
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T3049299559"] = "Please provide a title"
-- Upload documents for input
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T3064715989"] = "Upload documents for input"
-- Create Slides
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T3079776593"] = "Create Slides"

View File

@ -3,8 +3,9 @@
<MudTextField T="string" @bind-Text="@this.inputTitle" Validation="@this.ValidatingTitle" Adornment="Adornment.Start" Label="@T("Your title")" Variant="Variant.Outlined" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<MudTextField T="string" @bind-Text="@this.inputContext" Validation="@this.ValidatingContext" Adornment="Adornment.Start" Lines="6" MaxLines="12" AutoGrow="@false" Label="@T("Your content")" Variant="Variant.Outlined" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<ReadFileContent @bind-FileContent="@this.inputContext"/>
<MudTextField T="string" @bind-Text="@this.inputContext" Adornment="Adornment.Start" Lines="6" MaxLines="12" AutoGrow="@false" Label="@T("Your content")" Variant="Variant.Outlined" Class="mb-3" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
<MudText Typo="Typo.h5" Class="mb-1 mt-6"> @T("Upload documents for input")</MudText>
<AttachDocuments Name="Upload documents for input" Layer="@DropLayers.ASSISTANTS" @bind-DocumentPaths="@this.loadedDocumentPaths" CatchAllDocuments="true" UseSmallForm="false" Provider="@this.providerSettings"/>
<MudTextField T="string" AutoGrow="true" Lines="2" @bind-Text="@this.importantAspects" class="mb-3" Label="@T("(Optional) Important Aspects")" HelperText="@T("(Optional) Specify aspects that the LLM should consider when creating the slides. For example, the use of emojis or specific topics that should be highlighted.")" ShrinkLabel="true" Variant="Variant.Outlined" AdornmentIcon="@Icons.Material.Filled.List" Adornment="Adornment.Start"/>
<MudGrid>

View File

@ -1,4 +1,5 @@
using AIStudio.Chat;
using System.Text;
using AIStudio.Chat;
using AIStudio.Dialogs.Settings;
namespace AIStudio.Assistants.SlideBuilder;
@ -21,8 +22,8 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
- Translate PRESENTATION_TITLE in: {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}
# Content
- You get the following inputs: PRESENTATION_TITLE and PRESENTATION_CONTENT.
- You get the following inputs: PRESENTATION_TITLE, PRESENTATION_CONTENT, and any attached documents that may provide additional context or source material.
{{{this.PromptImportantAspects()}}}
# Subheadings
@ -115,6 +116,7 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
private int timeSpecification;
private int calculatedNumberOfSlides = 0;
private string importantAspects = string.Empty;
private HashSet<FileAttachment> loadedDocumentPaths = [];
#region Overrides of ComponentBase
@ -168,7 +170,76 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
{this.importantAspects}
""";
}
private async Task<string> PromptLoadDocumentsContent()
{
if (this.loadedDocumentPaths.Count == 0)
return string.Empty;
var documents = this.loadedDocumentPaths.Where(n => n is { Exists: true, IsImage: false }).ToList();
var sb = new StringBuilder();
if (documents.Count > 0)
{
sb.AppendLine("""
# DOCUMENTS:
""");
}
var numDocuments = 1;
foreach (var document in documents)
{
if (document.IsForbidden)
{
this.Logger.LogWarning($"Skipping forbidden file: '{document.FilePath}'.");
continue;
}
var fileContent = await this.RustService.ReadArbitraryFileData(document.FilePath, int.MaxValue);
sb.AppendLine($"""
## DOCUMENT {numDocuments}:
File path: {document.FilePath}
Content:
```
{fileContent}
```
---
""");
numDocuments++;
}
var numImages = this.loadedDocumentPaths.Count(x => x is { IsImage: true, Exists: true });
if (numImages > 0)
{
if (documents.Count == 0)
{
sb.AppendLine($"""
There are {numImages} image file(s) attached as documents.
Please consider them as documents as well and use them to
answer accordingly.
""");
}
else
{
sb.AppendLine($"""
Additionally, there are {numImages} image file(s) attached.
Please consider them as documents as well and use them to
answer accordingly.
""");
}
}
return sb.ToString();
}
private async Task CreateSlideBuilder()
{
await this.form!.Validate();
@ -178,6 +249,9 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
this.calculatedNumberOfSlides = this.timeSpecification > 0 ? this.CalculateNumberOfSlides() : 0;
this.CreateChatThread();
var documentContent = await this.PromptLoadDocumentsContent();
var imageAttachments = this.loadedDocumentPaths.Where(n => n is { Exists: true, IsImage: true }).ToList();
var time = this.AddUserRequest(
$"""
# PRESENTATION_TITLE
@ -189,9 +263,11 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
```
{this.inputContext}
{documentContent}
```
""",
hideContentFromUser: true);
hideContentFromUser: true,
imageAttachments);
await this.AddAIResponseAsync(time);
}