mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-05 08:24:35 +00:00
Added whole documents to the Translation, Grammar & Spelling, and Rewrite & Improve assistants (#1179)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f7666861f1
commit
918572c158
150 files changed
+12850
-302
No files matched your search
@@ -0,0 +1,3 @@
|
||||
<MudTooltip Text="@this.Tooltip">
|
||||
<MudIconButton Variant="Variant.Text" Icon="@AppIcons.SWITCH_ASSISTANT_MODE" Disabled="@this.Disabled" OnClick="@this.OnSwitch"/>
|
||||
</MudTooltip>
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// The button next to the settings of an assistant, which switches to another of the modes it offers, e.g., from
|
||||
/// translating a document to translating a text.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every assistant with modes shows the same icon here, so that users recognize the button; its tooltip names
|
||||
/// where it leads.
|
||||
/// </remarks>
|
||||
public partial class AssistantModeSwitch : ComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The tooltip of the button, e.g., "Switch to text translation".
|
||||
/// </summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string Tooltip { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the button is disabled, e.g., while the assistant works.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when the user clicks the button.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback OnSwitch { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
@using AIStudio.Tools.DocumentSegments
|
||||
@inherits MSGComponentBase
|
||||
|
||||
<MudPaper Class="pa-3 mb-3 border-dashed border rounded-lg">
|
||||
<MudText Typo="Typo.h6" Class="mb-2">
|
||||
@this.Title
|
||||
</MudText>
|
||||
<MudJustifiedText Typo="Typo.body1">
|
||||
@this.DoneText
|
||||
</MudJustifiedText>
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@this.SectionsText
|
||||
</MudJustifiedText>
|
||||
@if (this.Document.Results.CountOf(SegmentStatus.FILTERED) is > 0 and var filteredCount)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@string.Format(T("Sections left unchanged because the prompt injection check found suspicious content in them: {0}"), filteredCount)
|
||||
</MudJustifiedText>
|
||||
}
|
||||
@if (this.Document.Results.CountOf(SegmentStatus.FAILED) is > 0 and var failedCount)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body2">
|
||||
@string.Format(T("Sections left unchanged because the AI model gave no usable answer for them: {0}"), failedCount)
|
||||
</MudJustifiedText>
|
||||
}
|
||||
@if (DocumentSegmentFormats.For(this.Document.SourcePath) is { } format)
|
||||
{
|
||||
<MudJustifiedText Typo="Typo.body2" Class="mt-2">
|
||||
@format.LimitsNotice
|
||||
</MudJustifiedText>
|
||||
}
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@AppIcons.SAVE" Disabled="@this.IsSaving" OnClick="@this.Save" Class="mt-3">
|
||||
@this.SaveText
|
||||
</MudButton>
|
||||
</MudPaper>
|
||||
@@ -0,0 +1,59 @@
|
||||
using AIStudio.Assistants;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Tells the user what became of a document an assistant worked on, and lets them save the new document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It counts the sections which stayed as they were and names what the format of the document leaves alone.
|
||||
/// The texts which name what the assistant did come from the assistant.
|
||||
/// </remarks>
|
||||
public partial class EditedDocumentSummary : MSGComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The document the assistant worked on.
|
||||
/// </summary>
|
||||
[Parameter, EditorRequired]
|
||||
public EditedDocument Document { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// What the result is called, e.g., "Translated document".
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// What became of the document, e.g., into which language it was translated.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string DoneText { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// How many sections of the document the assistant changed.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string SectionsText { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The text of the button which saves the new document.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string SaveText { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the new document is being saved right now, which disables the button.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool IsSaving { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when the user wants to save the new document.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback OnSave { get; set; }
|
||||
|
||||
private async Task Save() => await this.OnSave.InvokeAsync();
|
||||
}
|
||||
@@ -20,7 +20,7 @@ else
|
||||
@<MudStack Row="@true" Spacing="3" Class="mb-3" StretchItems="StretchItems.None" AlignItems="AlignItems.Center">
|
||||
<MudTextField
|
||||
T="string"
|
||||
Text="@this.Directory"
|
||||
Value="@this.Directory"
|
||||
Label="@this.Label"
|
||||
ReadOnly="@true"
|
||||
Validation="@this.Validation"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
@inherits MSGComponentBase
|
||||
|
||||
<SelectFile File="@this.Document" FileChanged="@this.DocumentChanged" Label="@T("Document")" FileDialogTitle="@this.DialogTitle" Filter="@this.Filter" Validation="@this.Validate" Disabled="@this.Disabled" EnableDragDrop="@true" CatchAllDocuments="@true"/>
|
||||
@@ -0,0 +1,73 @@
|
||||
using AIStudio.Tools.DocumentSegments;
|
||||
using AIStudio.Tools.Rust;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// The field with which the user chooses the document an assistant works on, e.g., to translate it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It offers the kinds of files of all document formats and refuses any other file, see DocumentSegmentFormats, as
|
||||
/// well as a document whose text is larger than its format reads on this computer, see IDocumentSegmentFormat.MaxTextSize.
|
||||
/// </remarks>
|
||||
public partial class SelectDocument : MSGComponentBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The path of the chosen document; empty while none is chosen.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string Document { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Called with the path of the document the user chose.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<string> DocumentChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The title of the file dialog, e.g., "Select a document to translate".
|
||||
/// </summary>
|
||||
[Parameter, EditorRequired]
|
||||
public string DialogTitle { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the field is disabled, e.g., while the assistant works.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
// Built anew, since the name of the entry follows the language of the user interface:
|
||||
private FileTypeFilter[] Filter => [DocumentSegmentFormats.AllKinds];
|
||||
|
||||
private string? Validate(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
return TA("Please choose a document.");
|
||||
|
||||
if (DocumentSegmentFormats.For(path) is not { } format)
|
||||
return TA("This kind of file is not supported. Please choose a Word, PowerPoint, LaTeX, Markdown, or HTML file.");
|
||||
|
||||
if (TextSizeOf(format, path) is { } textSize && textSize > format.MaxTextSize)
|
||||
return string.Format(TA("The text of this document takes {0} MB, more than the {1} MB which AI Studio can edit for this kind of document with the memory of this computer. Please split it into smaller files or choose another one."), DocumentMemoryBudget.MegabytesOf(textSize), DocumentMemoryBudget.MegabytesOf(format.MaxTextSize));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures the text of a document; null when the document cannot be read, e.g., because it is gone or broken,
|
||||
/// which the run reports then.
|
||||
/// </summary>
|
||||
private static long? TextSizeOf(IDocumentSegmentFormat format, string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.Exists(path) ? format.TextSizeOf(path) : null;
|
||||
}
|
||||
catch (Exception e) when (e is IOException or InvalidDataException or UnauthorizedAccessException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ else
|
||||
@<MudStack Row="@true" Spacing="3" Class="mb-3" StretchItems="StretchItems.None" AlignItems="AlignItems.Center">
|
||||
<MudTextField
|
||||
T="string"
|
||||
Text="@this.File"
|
||||
Value="@this.File"
|
||||
Label="@this.Label"
|
||||
ReadOnly="@true"
|
||||
Validation="@this.Validation"
|
||||
|
||||
Reference in new issue
Block a user