mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-11 08:47:21 +00:00
Turned getter-like extension methods into extension properties (#1157)
This commit is contained in:
1 parent
0375318b1b
commit
f649febf88
286 files changed
+1379
-1109
No files matched your search
@@ -12,8 +12,8 @@ public static class ChatRoleExtensions
|
||||
/// <summary>
|
||||
/// Returns the name of the role.
|
||||
/// </summary>
|
||||
/// <returns>The name of the role.</returns>
|
||||
public string ToName() => role switch
|
||||
/// <value>The name of the role.</value>
|
||||
public string Name => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => TB("System"),
|
||||
ChatRole.USER => TB("You"),
|
||||
@@ -25,8 +25,8 @@ public static class ChatRoleExtensions
|
||||
/// <summary>
|
||||
/// Returns the color of the role.
|
||||
/// </summary>
|
||||
/// <returns>The color of the role.</returns>
|
||||
public Color ToColor() => role switch
|
||||
/// <value>The color of the role.</value>
|
||||
public Color Color => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => Color.Info,
|
||||
ChatRole.USER => Color.Primary,
|
||||
@@ -38,8 +38,8 @@ public static class ChatRoleExtensions
|
||||
/// <summary>
|
||||
/// Returns the icon of the role.
|
||||
/// </summary>
|
||||
/// <returns>The icon of the role.</returns>
|
||||
public string ToIcon() => role switch
|
||||
/// <value>The icon of the role.</value>
|
||||
public string Icon => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => Icons.Material.Filled.Settings,
|
||||
ChatRole.USER => Icons.Material.Filled.Person,
|
||||
@@ -51,8 +51,8 @@ public static class ChatRoleExtensions
|
||||
/// <summary>
|
||||
/// Returns the specific name of the role for the chat template.
|
||||
/// </summary>
|
||||
/// <returns>The name of the role.</returns>
|
||||
public string ToChatTemplateName() => role switch
|
||||
/// <value>The name of the role.</value>
|
||||
public string ChatTemplateName => role switch
|
||||
{
|
||||
ChatRole.SYSTEM => TB("System"),
|
||||
ChatRole.USER => TB("User"),
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
<MudCard Class="@this.CardClasses" Outlined="@true">
|
||||
<MudCardHeader>
|
||||
<CardHeaderAvatar>
|
||||
<MudAvatar Color="@this.Role.ToColor()">
|
||||
<MudIcon Icon="@this.Role.ToIcon()"/>
|
||||
<MudAvatar Color="@this.Role.Color">
|
||||
<MudIcon Icon="@this.Role.Icon"/>
|
||||
</MudAvatar>
|
||||
</CardHeaderAvatar>
|
||||
<CardHeaderContent>
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="2">
|
||||
<MudText Typo="Typo.body1">
|
||||
@this.Role.ToName() (@this.Time.LocalDateTime)
|
||||
@this.Role.Name (@this.Time.LocalDateTime)
|
||||
</MudText>
|
||||
@if (this.HasToolTrace)
|
||||
{
|
||||
@@ -87,9 +87,9 @@
|
||||
{
|
||||
<MudTooltip Text="@this.EffectiveExportTitle" Placement="Placement.Bottom">
|
||||
<MudMenu Icon="@Icons.Material.Filled.Save" MaxHeight="@MenuDefaults.MAX_HEIGHT">
|
||||
@foreach (var documentFormat in FileExportFormatExtensions.DOCUMENT_FORMATS)
|
||||
@foreach (var documentFormat in FileExportFormat.DocumentFormats)
|
||||
{
|
||||
<MudMenuItem OnClick="@(() => this.ExportDocument(documentFormat))" Icon="@documentFormat.ToIcon()" Label="@documentFormat.ToName()"/>
|
||||
<MudMenuItem OnClick="@(() => this.ExportDocument(documentFormat))" Icon="@documentFormat.Icon" Label="@documentFormat.Name"/>
|
||||
}
|
||||
@if (this.MessageFiles.Count > MAX_FILES_WITHOUT_SUBMENUS)
|
||||
{
|
||||
@@ -113,9 +113,9 @@
|
||||
}
|
||||
}
|
||||
<MudDivider/>
|
||||
@foreach (var textFormat in FileExportFormatExtensions.TEXT_FORMATS)
|
||||
@foreach (var textFormat in FileExportFormat.TextFormats)
|
||||
{
|
||||
<MudMenuItem OnClick="@(() => this.ExportDocument(textFormat))" Icon="@textFormat.ToIcon()" Label="@textFormat.ToName()"/>
|
||||
<MudMenuItem OnClick="@(() => this.ExportDocument(textFormat))" Icon="@textFormat.Icon" Label="@textFormat.Name"/>
|
||||
}
|
||||
</MudMenu>
|
||||
</MudTooltip>
|
||||
@@ -126,7 +126,7 @@
|
||||
<MudMenu Icon="@Icons.Material.Filled.Apps" Disabled="@(!this.IsSendToEnabled)" MaxHeight="@MenuDefaults.MAX_HEIGHT">
|
||||
@foreach (var destination in this.SendToDestinations)
|
||||
{
|
||||
<MudMenuItem OnClick="@(() => this.SendTo(destination))" Label="@destination.Name()"/>
|
||||
<MudMenuItem OnClick="@(() => this.SendTo(destination))" Label="@destination.Name"/>
|
||||
}
|
||||
</MudMenu>
|
||||
</MudTooltip>
|
||||
|
||||
@@ -274,8 +274,8 @@ public partial class ContentBlockComponent : MSGComponentBase
|
||||
/// </remarks>
|
||||
private string ExportLabel(MessageFile file)
|
||||
{
|
||||
var isTable = file.Format.IsTabular();
|
||||
var filesOfItsKind = this.MessageFiles.Where(entry => entry.Format.IsTabular() == isTable).ToList();
|
||||
var isTable = file.Format.IsTabular;
|
||||
var filesOfItsKind = this.MessageFiles.Where(entry => entry.Format.IsTabular == isTable).ToList();
|
||||
var extensionOrName = file.ToFileExtensionOrName();
|
||||
var typeName = file.ToName();
|
||||
|
||||
@@ -308,7 +308,7 @@ public partial class ContentBlockComponent : MSGComponentBase
|
||||
/// for the entire answer out of sight. Each submenu keeps the order of the answer, so "Code
|
||||
/// block 3" is the third entry of its submenu as well.
|
||||
/// </remarks>
|
||||
private IEnumerable<IGrouping<bool, MessageFile>> MessageFilesByKind => this.MessageFiles.GroupBy(file => file.Format.IsTabular()).OrderByDescending(isTable => isTable.Key);
|
||||
private IEnumerable<IGrouping<bool, MessageFile>> MessageFilesByKind => this.MessageFiles.GroupBy(file => file.Format.IsTabular).OrderByDescending(isTable => isTable.Key);
|
||||
|
||||
/// <summary>
|
||||
/// Names the submenu of one kind of files in the export menu, with the number of its files.
|
||||
@@ -322,7 +322,7 @@ public partial class ContentBlockComponent : MSGComponentBase
|
||||
/// <summary>
|
||||
/// Returns the icon of the submenu of one kind of files in the export menu.
|
||||
/// </summary>
|
||||
private static string ExportGroupIcon(IGrouping<bool, MessageFile> filesOfAKind) => filesOfAKind.Key ? FileExportFormat.CSV.ToIcon() : FileExportFormat.SOURCE_CODE.ToIcon();
|
||||
private static string ExportGroupIcon(IGrouping<bool, MessageFile> filesOfAKind) => filesOfAKind.Key ? FileExportFormat.CSV.Icon : FileExportFormat.SOURCE_CODE.Icon;
|
||||
|
||||
/// <summary>
|
||||
/// What the export offers, falling back to the chat wording when nobody named it.
|
||||
@@ -649,7 +649,7 @@ public partial class ContentBlockComponent : MSGComponentBase
|
||||
// here which would fall out of sync with the one in FileExportFormatExtensions.
|
||||
//
|
||||
var disclosureService = this.GetsAIGeneratedContentDisclosure ? this.DisclosureService : null;
|
||||
if (format.UsesPandoc())
|
||||
if (format.UsesPandoc)
|
||||
await PandocExport.ToDocument(this.RustService, this.PandocAvailability, disclosureService, this.EffectiveExportTitle, format, this.Content, this.ExportFileName);
|
||||
else if (this.Content.TryGetExportMarkdown(out var markdown))
|
||||
await PlainFileExport.ToFile(this.RustService, this.EffectiveExportTitle, format, disclosureService?.AddDisclosureToMarkdown(markdown) ?? markdown, this.ExportFileName);
|
||||
|
||||
@@ -127,7 +127,7 @@ public sealed class ContentText : IContent
|
||||
try
|
||||
{
|
||||
// Most answers, those of the agents among them, received nothing to store, and need no database:
|
||||
if (!this.SourcePassages.Any(passage => passage.HoldsTextsToStore()))
|
||||
if (!this.SourcePassages.Any(passage => passage.HoldsTextsToStore))
|
||||
return;
|
||||
|
||||
if (await ChatProvenance.GetStoreAsync() is { } store && await this.StoreReceivedContentAsync(store, chatId))
|
||||
@@ -158,7 +158,7 @@ public sealed class ContentText : IContent
|
||||
var passages = new List<SourcePassage>(this.SourcePassages.Count);
|
||||
foreach (var passage in this.SourcePassages)
|
||||
{
|
||||
if (!passage.HoldsTextsToStore())
|
||||
if (!passage.HoldsTextsToStore)
|
||||
{
|
||||
passages.Add(passage);
|
||||
continue;
|
||||
@@ -168,7 +168,7 @@ public sealed class ContentText : IContent
|
||||
try
|
||||
{
|
||||
// Not cancellable: the answer is complete, also when the user stopped it.
|
||||
provenanceId = await store.StoreAsync(chatId, passage.GetProvenanceKind(), passage.Text, passage.SurroundingContent, CancellationToken.None);
|
||||
provenanceId = await store.StoreAsync(chatId, passage.ProvenanceKind, passage.Text, passage.SurroundingContent, CancellationToken.None);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
@@ -95,13 +95,13 @@ public static class IContentExtensions
|
||||
/// <returns>The content of the file to write.</returns>
|
||||
public string ToExportContent(MessageFile file)
|
||||
{
|
||||
if (file.Format.IsTabular())
|
||||
if (file.Format.IsTabular)
|
||||
return file.Content;
|
||||
|
||||
if (file.Format is FileExportFormat.SOURCE_CODE)
|
||||
return ToSourceCodeFile(file);
|
||||
|
||||
var sources = content.Sources.ToExportMarkdown(file.Format.FollowsPageAnchors());
|
||||
var sources = content.Sources.ToExportMarkdown(file.Format.FollowsPageAnchors);
|
||||
if (file.Format is FileExportFormat.MARKDOWN)
|
||||
return AppendSources(file.Content, sources);
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ public static class IImageSourceExtensions
|
||||
/// <returns>The size limit of one image file.</returns>
|
||||
public static long MaxImageSizeBytesFor(AIStudio.Settings.Provider provider)
|
||||
{
|
||||
var engineLimit = provider.UsedLLMProvider is LLMProviders.SELF_HOSTED ? provider.Host.GetMaxImageSizeBytes() : null;
|
||||
var providerLimit = provider.UsedLLMProvider.GetMaxImageSizeBytes();
|
||||
var engineLimit = provider.UsedLLMProvider is LLMProviders.SELF_HOSTED ? provider.Host.MaxImageSizeBytes : null;
|
||||
var providerLimit = provider.UsedLLMProvider.MaxImageSizeBytes;
|
||||
return Math.Min(Math.Min(engineLimit ?? MAX_IMAGE_SIZE_BYTES, providerLimit ?? MAX_IMAGE_SIZE_BYTES), MAX_IMAGE_SIZE_BYTES);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user