mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-27 03:53:36 +00:00
Rename message tables to message files
This commit is contained in:
parent
fdaa12ab5b
commit
5ce16f3f24
@ -91,12 +91,12 @@
|
|||||||
{
|
{
|
||||||
<MudMenuItem OnClick="@(() => this.ExportDocument(documentFormat))" Icon="@documentFormat.ToIcon()" Label="@documentFormat.ToName()"/>
|
<MudMenuItem OnClick="@(() => this.ExportDocument(documentFormat))" Icon="@documentFormat.ToIcon()" Label="@documentFormat.ToName()"/>
|
||||||
}
|
}
|
||||||
@if (this.MessageTables.Count > 0)
|
@if (this.MessageFiles.Count > 0)
|
||||||
{
|
{
|
||||||
<MudDivider/>
|
<MudDivider/>
|
||||||
@foreach (var messageTable in this.MessageTables)
|
@foreach (var messageFile in this.MessageFiles)
|
||||||
{
|
{
|
||||||
<MudMenuItem OnClick="@(() => this.ExportTable(messageTable))" Icon="@messageTable.Format.ToIcon()" Label="@this.ExportLabel(messageTable)"/>
|
<MudMenuItem OnClick="@(() => this.ExportFile(messageFile))" Icon="@messageFile.Format.ToIcon()" Label="@this.ExportLabel(messageFile)"/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<MudDivider/>
|
<MudDivider/>
|
||||||
|
|||||||
@ -125,8 +125,8 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
private int lastRenderHash;
|
private int lastRenderHash;
|
||||||
private string cachedMarkdownRenderPlanInput = string.Empty;
|
private string cachedMarkdownRenderPlanInput = string.Empty;
|
||||||
private MarkdownRenderPlan cachedMarkdownRenderPlan = MarkdownRenderPlan.EMPTY;
|
private MarkdownRenderPlan cachedMarkdownRenderPlan = MarkdownRenderPlan.EMPTY;
|
||||||
private string cachedMessageTablesInput = string.Empty;
|
private string cachedMessageFilesInput = string.Empty;
|
||||||
private IReadOnlyList<MessageTable> cachedMessageTables = [];
|
private IReadOnlyList<MessageFile> cachedMessageFiles = [];
|
||||||
private char csvSeparator = ',';
|
private char csvSeparator = ',';
|
||||||
private ElementReference mathContentContainer;
|
private ElementReference mathContentContainer;
|
||||||
private SourcesList? sourcesList;
|
private SourcesList? sourcesList;
|
||||||
@ -154,19 +154,19 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
/// message, and a block re-renders for reasons which have nothing to do with its text, such as
|
/// message, and a block re-renders for reasons which have nothing to do with its text, such as
|
||||||
/// switching the theme, which would parse every message of a long chat again.
|
/// switching the theme, which would parse every message of a long chat again.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private IReadOnlyList<MessageTable> MessageTables
|
private IReadOnlyList<MessageFile> MessageFiles
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!this.Content.TryGetMarkdownText(out var markdown))
|
if (!this.Content.TryGetMarkdownText(out var markdown))
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
if (ReferenceEquals(this.cachedMessageTablesInput, markdown) || string.Equals(this.cachedMessageTablesInput, markdown, StringComparison.Ordinal))
|
if (ReferenceEquals(this.cachedMessageFilesInput, markdown) || string.Equals(this.cachedMessageFilesInput, markdown, StringComparison.Ordinal))
|
||||||
return this.cachedMessageTables;
|
return this.cachedMessageFiles;
|
||||||
|
|
||||||
this.cachedMessageTablesInput = markdown;
|
this.cachedMessageFilesInput = markdown;
|
||||||
this.cachedMessageTables = PlainFileExport.ExtractTables(markdown, this.csvSeparator);
|
this.cachedMessageFiles = PlainFileExport.ExtractFiles(markdown, this.csvSeparator);
|
||||||
return this.cachedMessageTables;
|
return this.cachedMessageFiles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,9 +178,9 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
/// one, the user has to be able to tell them apart: the heading above a table does that, unless
|
/// one, the user has to be able to tell them apart: the heading above a table does that, unless
|
||||||
/// it is missing or two tables share one, and then we count them.
|
/// it is missing or two tables share one, and then we count them.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private string ExportLabel(MessageTable table)
|
private string ExportLabel(MessageFile table)
|
||||||
{
|
{
|
||||||
var tables = this.MessageTables;
|
var tables = this.MessageFiles;
|
||||||
if (tables.Count < 2)
|
if (tables.Count < 2)
|
||||||
return table.Format.ToName();
|
return table.Format.ToName();
|
||||||
|
|
||||||
@ -221,8 +221,8 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
this.csvSeparator = separator;
|
this.csvSeparator = separator;
|
||||||
this.cachedMessageTablesInput = string.Empty;
|
this.cachedMessageFilesInput = string.Empty;
|
||||||
this.cachedMessageTables = [];
|
this.cachedMessageFiles = [];
|
||||||
await this.InvokeAsync(this.StateHasChanged);
|
await this.InvokeAsync(this.StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -749,17 +749,17 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exports one table out of the message, exactly as the menu offered it.
|
/// Exports one file out of the message, exactly as the menu offered it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task ExportTable(MessageTable table)
|
private async Task ExportFile(MessageFile file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PlainFileExport.ToFile(this.RustService, this.EffectiveExportTitle, table.Format, table.Content, table.Caption);
|
await PlainFileExport.ToFile(this.RustService, this.EffectiveExportTitle, file.Format, file.Content, file.Caption);
|
||||||
}
|
}
|
||||||
catch (ArgumentOutOfRangeException e)
|
catch (ArgumentOutOfRangeException e)
|
||||||
{
|
{
|
||||||
await this.ReportUnknownExportFormat(e, table.Format);
|
await this.ReportUnknownExportFormat(e, file.Format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
namespace AIStudio.Tools;
|
namespace AIStudio.Tools;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A table found in a message, ready to be written to a file.
|
/// A file found in a message, ready to be written: a table the model wrote.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Ordinal">Which table of the message this is, counting from one. The same table
|
/// <param name="Ordinal">Which table of the message this is, counting from one. The same table
|
||||||
/// appears once per format we offer for it, so this is what tells two tables apart even when they
|
/// appears once per format we offer for it, so this is what tells two tables apart even when they
|
||||||
@ -9,4 +9,4 @@ namespace AIStudio.Tools;
|
|||||||
/// <param name="Caption">What the table is about, taken from its first column heading.</param>
|
/// <param name="Caption">What the table is about, taken from its first column heading.</param>
|
||||||
/// <param name="Format">The format this content is written as.</param>
|
/// <param name="Format">The format this content is written as.</param>
|
||||||
/// <param name="Content">The finished file content.</param>
|
/// <param name="Content">The finished file content.</param>
|
||||||
public sealed record MessageTable(int Ordinal, string Caption, FileExportFormat Format, string Content);
|
public sealed record MessageFile(int Ordinal, string Caption, FileExportFormat Format, string Content);
|
||||||
@ -27,7 +27,7 @@ public static class PlainFileExport
|
|||||||
/// <param name="markdown">The Markdown text of the message.</param>
|
/// <param name="markdown">The Markdown text of the message.</param>
|
||||||
/// <param name="separator">The separator to write a Markdown table with, see CsvWriter.SeparatorFor.</param>
|
/// <param name="separator">The separator to write a Markdown table with, see CsvWriter.SeparatorFor.</param>
|
||||||
/// <returns>The tables, or an empty list when the message holds none.</returns>
|
/// <returns>The tables, or an empty list when the message holds none.</returns>
|
||||||
public static IReadOnlyList<MessageTable> ExtractTables(string markdown, char separator)
|
public static IReadOnlyList<MessageFile> ExtractFiles(string markdown, char separator)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(markdown))
|
if (string.IsNullOrWhiteSpace(markdown))
|
||||||
return [];
|
return [];
|
||||||
@ -59,7 +59,7 @@ public static class PlainFileExport
|
|||||||
return tables.Concat(codeBlocks)
|
return tables.Concat(codeBlocks)
|
||||||
.Where(entry => entry.Content is not null)
|
.Where(entry => entry.Content is not null)
|
||||||
.OrderBy(entry => entry.Line)
|
.OrderBy(entry => entry.Line)
|
||||||
.Select((entry, index) => new MessageTable(
|
.Select((entry, index) => new MessageFile(
|
||||||
index + 1,
|
index + 1,
|
||||||
Caption: HeadingAbove(entry.Line) is { Length: > 0 } heading ? heading : entry.Content!.Value.Fallback,
|
Caption: HeadingAbove(entry.Line) is { Length: > 0 } heading ? heading : entry.Content!.Value.Fallback,
|
||||||
entry.Content!.Value.Format,
|
entry.Content!.Value.Format,
|
||||||
|
|||||||
@ -163,7 +163,7 @@ public sealed class IContentExtensionsTests
|
|||||||
"| Q1 | 100 |"), TOOL_SOURCE);
|
"| Q1 | 100 |"), TOOL_SOURCE);
|
||||||
|
|
||||||
content.TryGetMarkdownText(out var markdown);
|
content.TryGetMarkdownText(out var markdown);
|
||||||
var tables = PlainFileExport.ExtractTables(markdown, ',');
|
var tables = PlainFileExport.ExtractFiles(markdown, ',');
|
||||||
|
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user