mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-07 05:29:40 +00:00
Reduced memory usage and fixed several memory leaks (#933)
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Sync Flatpak repo (push) Has been cancelled
Build and Release / Collect Flatpak artifacts (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Sync Flatpak repo (push) Has been cancelled
Build and Release / Collect Flatpak artifacts (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
This commit is contained in:
1 parent
902a01a4d0
commit
7d9a4f5ab1
51 files changed
+531
-85
No files matched your search
@@ -15,7 +15,7 @@ using RetrievalInfo = AIStudio.Tools.ERIClient.DataModel.RetrievalInfo;
|
||||
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
public partial class DataSourceERI_V1InfoDialog : MSGComponentBase, IAsyncDisposable, ISecretId
|
||||
public partial class DataSourceERI_V1InfoDialog : MSGComponentBase, ISecretId
|
||||
{
|
||||
[CascadingParameter]
|
||||
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||
@@ -186,9 +186,9 @@ public partial class DataSourceERI_V1InfoDialog : MSGComponentBase, IAsyncDispos
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IDisposable
|
||||
#region Overrides of MSGComponentBase
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
protected override async ValueTask DisposeResourcesAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ using Timer = System.Timers.Timer;
|
||||
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
public partial class DataSourceLocalDirectoryInfoDialog : MSGComponentBase, IAsyncDisposable
|
||||
public partial class DataSourceLocalDirectoryInfoDialog : MSGComponentBase
|
||||
{
|
||||
[CascadingParameter]
|
||||
private IMudDialogInstance MudDialog { get; set; } = null!;
|
||||
@@ -89,9 +89,9 @@ public partial class DataSourceLocalDirectoryInfoDialog : MSGComponentBase, IAsy
|
||||
this.MudDialog.Close();
|
||||
}
|
||||
|
||||
#region Implementation of IDisposable
|
||||
#region Overrides of MSGComponentBase
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
protected override async ValueTask DisposeResourcesAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
@if (this.Document is null)
|
||||
{
|
||||
<ReadFileContent Text="@T("Load file")" @bind-FileContent="@this.FileContent" EnableDragDrop="true" Layer="@DropLayers.DIALOGS" CatchAllDocuments="true"/>
|
||||
<ReadFileContent Text="@T("Load file")" FileContent="@this.FileContent" FileContentChanged="@this.ApplyLoadedFileContent" EnableDragDrop="true" Layer="@DropLayers.DIALOGS" CatchAllDocuments="true"/>
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -51,6 +51,13 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (this.previewCutOffCharacters > 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Variant="Variant.Outlined" Class="my-2">
|
||||
@string.Format(T("Your document is large, so we show you only its beginning. We hide the remaining {0:N0} characters here. Rest assured: the AI still receives your entire document."), this.previewCutOffCharacters)
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
<MudTabs Elevation="0" Rounded="true" ApplyEffectsToContainer="true" Outlined="true" PanelClass="pa-2" Class="mb-2">
|
||||
@if (this.Document?.IsImage ?? false)
|
||||
{
|
||||
@@ -70,14 +77,14 @@
|
||||
Class="ma-2 pe-4"
|
||||
HelperText="@T("This is the content we loaded from your file — including headings, lists, and formatting. Use this to verify your file loads as expected.")">
|
||||
<div style="max-height: 40vh; overflow-y: auto;">
|
||||
<MudMarkdown Value="@this.FileContent" Props="Markdown.DefaultConfig" Styling="@this.MarkdownStyling" MarkdownPipeline="Markdown.SAFE_MARKDOWN_PIPELINE"/>
|
||||
<MudMarkdown Value="@this.previewContent" Props="Markdown.DefaultConfig" Styling="@this.MarkdownStyling" MarkdownPipeline="Markdown.SAFE_MARKDOWN_PIPELINE"/>
|
||||
</div>
|
||||
</MudField>
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="@T("Simple View")" Icon="@Icons.Material.Filled.Terminal">
|
||||
<MudTextField
|
||||
T="string"
|
||||
@bind-Text="@this.FileContent"
|
||||
Text="@this.previewContent"
|
||||
AdornmentIcon="@Icons.Material.Filled.Article"
|
||||
Adornment="Adornment.Start"
|
||||
Immediate="@true"
|
||||
|
||||
@@ -21,11 +21,41 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
||||
[Parameter]
|
||||
public string FileContent { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// How many characters we show at most. Rendering a huge document costs us a large Markdown
|
||||
/// syntax tree and an equally large render tree. This dialog answers the question of how we
|
||||
/// read the file, though — the beginning of the document is enough for that, and the AI still
|
||||
/// receives the entire content.
|
||||
/// </summary>
|
||||
private const int PREVIEW_CHARACTER_LIMIT = 200_000;
|
||||
|
||||
/// <summary>
|
||||
/// Set when reading the file failed, so the dialog shows the reason instead of empty content.
|
||||
/// </summary>
|
||||
private string? loadFailureMessage;
|
||||
|
||||
/// <summary>
|
||||
/// What we show to the user: either the entire file content, or its beginning. We keep this in
|
||||
/// its own field so that we cut the content only once, instead of on every render.
|
||||
/// </summary>
|
||||
private string previewContent = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// How many characters we cut off from the preview. Zero when we show the entire content.
|
||||
/// </summary>
|
||||
private int previewCutOffCharacters;
|
||||
|
||||
/// <summary>
|
||||
/// Ends the extraction when this dialog is gone before the file was read completely.
|
||||
/// </summary>
|
||||
private readonly CancellationTokenSource extractionCancellation = new();
|
||||
|
||||
/// <summary>
|
||||
/// True once this dialog was disposed. The extraction runs across awaits, so it may return
|
||||
/// long after the user closed the dialog — it must not touch this component afterwards.
|
||||
/// </summary>
|
||||
private bool isDisposed;
|
||||
|
||||
/// <summary>
|
||||
/// True while we extract the file content. Reading happens after the first render, so the
|
||||
/// dialog can tell the user that it is working instead of showing an empty document.
|
||||
@@ -54,6 +84,7 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
||||
this.Document.Exists &&
|
||||
string.IsNullOrWhiteSpace(this.FileContent);
|
||||
|
||||
this.UpdatePreview();
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
@@ -66,7 +97,10 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
||||
|
||||
try
|
||||
{
|
||||
var extraction = await UserFile.LoadFileData(this.Document.FilePath, this.RustService, this.DialogService);
|
||||
var extraction = await UserFile.LoadFileData(this.Document.FilePath, this.RustService, this.DialogService, this.extractionCancellation.Token);
|
||||
if (this.isDisposed)
|
||||
return;
|
||||
|
||||
this.FileContent = extraction.Content;
|
||||
|
||||
//
|
||||
@@ -76,6 +110,10 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
||||
if (!extraction.HasUsableContent)
|
||||
this.loadFailureMessage = extraction.ToUserMessage(this.Document.FileName);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// The user closed this dialog while we were reading the file. Nothing left to do.
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex, "Failed to load file content from '{FilePath}'", this.Document);
|
||||
@@ -84,14 +122,67 @@ public partial class DocumentCheckDialog : MSGComponentBase
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.isLoadingContent = false;
|
||||
this.StateHasChanged();
|
||||
if (!this.isDisposed)
|
||||
{
|
||||
this.isLoadingContent = false;
|
||||
this.UpdatePreview();
|
||||
this.StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (firstRender)
|
||||
this.Logger.LogWarning("Document check dialog opened without a valid file path.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the user loads a file through this dialog. We don't use a two-way binding here,
|
||||
/// since we have to refresh the preview whenever the content changes.
|
||||
/// </summary>
|
||||
/// <param name="fileContent">The content of the file the user has loaded.</param>
|
||||
private void ApplyLoadedFileContent(string fileContent)
|
||||
{
|
||||
this.FileContent = fileContent;
|
||||
this.UpdatePreview();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines what part of the file content we show to the user.
|
||||
/// </summary>
|
||||
private void UpdatePreview()
|
||||
{
|
||||
if (this.FileContent.Length <= PREVIEW_CHARACTER_LIMIT)
|
||||
{
|
||||
this.previewContent = this.FileContent;
|
||||
this.previewCutOffCharacters = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// We cut at the last line break before our limit. Otherwise, we might tear apart a Markdown
|
||||
// construct like a table row or a code fence in the middle of a line:
|
||||
//
|
||||
var cutIndex = this.FileContent.LastIndexOf('\n', PREVIEW_CHARACTER_LIMIT - 1) + 1;
|
||||
if (cutIndex < 1)
|
||||
cutIndex = PREVIEW_CHARACTER_LIMIT;
|
||||
|
||||
this.previewContent = this.FileContent[..cutIndex];
|
||||
this.previewCutOffCharacters = this.FileContent.Length - cutIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends a running extraction. Without this, reading a large document would continue after the
|
||||
/// user closed this dialog and would keep this component, the extracted content, and the
|
||||
/// response stream alive until the runtime is done.
|
||||
/// </summary>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
this.isDisposed = true;
|
||||
this.extractionCancellation.Cancel();
|
||||
this.extractionCancellation.Dispose();
|
||||
|
||||
base.DisposeResources();
|
||||
}
|
||||
|
||||
private CodeBlockTheme CodeColorPalette => this.SettingsManager.IsDarkMode ? CodeBlockTheme.Dark : CodeBlockTheme.Default;
|
||||
|
||||
private MudMarkdownStyling MarkdownStyling => new()
|
||||
|
||||
Reference in new issue
Block a user