mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-03-30 19:51:37 +00:00
Add AttachDocuments option in SlideAssistant
This commit is contained in:
parent
7f5efc8044
commit
ec23b0c342
@ -1342,6 +1342,9 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T1790167032
|
|||||||
-- Slide Assistant
|
-- Slide Assistant
|
||||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T1883918574"] = "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
|
-- Target language
|
||||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T237828418"] = "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
|
-- Please provide a title
|
||||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T3049299559"] = "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
|
-- Create Slides
|
||||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T3079776593"] = "Create Slides"
|
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::SLIDEBUILDER::SLIDEASSISTANT::T3079776593"] = "Create Slides"
|
||||||
|
|
||||||
|
|||||||
@ -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.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"/>
|
<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"/>
|
||||||
<ReadFileContent @bind-FileContent="@this.inputContext"/>
|
<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"/>
|
<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>
|
<MudGrid>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using AIStudio.Chat;
|
using System.Text;
|
||||||
|
using AIStudio.Chat;
|
||||||
using AIStudio.Dialogs.Settings;
|
using AIStudio.Dialogs.Settings;
|
||||||
|
|
||||||
namespace AIStudio.Assistants.SlideBuilder;
|
namespace AIStudio.Assistants.SlideBuilder;
|
||||||
@ -21,7 +22,7 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
|
|||||||
- Translate PRESENTATION_TITLE in: {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}
|
- Translate PRESENTATION_TITLE in: {{{this.selectedTargetLanguage.PromptGeneralPurpose(this.customTargetLanguage)}}}
|
||||||
|
|
||||||
# Content
|
# 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()}}}
|
{{{this.PromptImportantAspects()}}}
|
||||||
|
|
||||||
@ -115,6 +116,7 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
|
|||||||
private int timeSpecification;
|
private int timeSpecification;
|
||||||
private int calculatedNumberOfSlides = 0;
|
private int calculatedNumberOfSlides = 0;
|
||||||
private string importantAspects = string.Empty;
|
private string importantAspects = string.Empty;
|
||||||
|
private HashSet<FileAttachment> loadedDocumentPaths = [];
|
||||||
|
|
||||||
#region Overrides of ComponentBase
|
#region Overrides of ComponentBase
|
||||||
|
|
||||||
@ -169,6 +171,75 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
|
|||||||
""";
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
private async Task CreateSlideBuilder()
|
||||||
{
|
{
|
||||||
await this.form!.Validate();
|
await this.form!.Validate();
|
||||||
@ -178,6 +249,9 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
|
|||||||
this.calculatedNumberOfSlides = this.timeSpecification > 0 ? this.CalculateNumberOfSlides() : 0;
|
this.calculatedNumberOfSlides = this.timeSpecification > 0 ? this.CalculateNumberOfSlides() : 0;
|
||||||
|
|
||||||
this.CreateChatThread();
|
this.CreateChatThread();
|
||||||
|
var documentContent = await this.PromptLoadDocumentsContent();
|
||||||
|
var imageAttachments = this.loadedDocumentPaths.Where(n => n is { Exists: true, IsImage: true }).ToList();
|
||||||
|
|
||||||
var time = this.AddUserRequest(
|
var time = this.AddUserRequest(
|
||||||
$"""
|
$"""
|
||||||
# PRESENTATION_TITLE
|
# PRESENTATION_TITLE
|
||||||
@ -189,9 +263,11 @@ public partial class SlideAssistant : AssistantBaseCore<SettingsDialogSlideBuild
|
|||||||
|
|
||||||
```
|
```
|
||||||
{this.inputContext}
|
{this.inputContext}
|
||||||
|
{documentContent}
|
||||||
```
|
```
|
||||||
""",
|
""",
|
||||||
hideContentFromUser: true);
|
hideContentFromUser: true,
|
||||||
|
imageAttachments);
|
||||||
|
|
||||||
await this.AddAIResponseAsync(time);
|
await this.AddAIResponseAsync(time);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user