mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-10 23: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
@@ -63,7 +63,7 @@
|
||||
@foreach (var source in Enum.GetValues<BatchProcessingPromptSource>())
|
||||
{
|
||||
<MudSelectItem Value="@source">
|
||||
@source.Name()
|
||||
@source.Name
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
@@ -149,7 +149,7 @@ else
|
||||
@foreach (var mode in Enum.GetValues<BatchProcessingOutputMode>())
|
||||
{
|
||||
<MudSelectItem Value="@mode">
|
||||
@mode.Name()
|
||||
@mode.Name
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
@@ -157,16 +157,16 @@ else
|
||||
@if (this.outputMode is BatchProcessingOutputMode.INDIVIDUAL_FILES)
|
||||
{
|
||||
<MudSelect T="FileExportFormat" @bind-Value="@this.resultFileFormat" Disabled="@this.isProcessingBatch" AdornmentIcon="@Icons.Material.Filled.Description" Adornment="Adornment.Start" Label="@T("File format")" HelperText="@T("Choose the format of the result files. Everything except Markdown is converted by Pandoc, which AI Studio offers to install when it is missing.")" Variant="Variant.Outlined" Margin="Margin.Dense" Class="mb-3">
|
||||
@foreach (var format in FileExportFormatExtensions.ANSWER_FORMATS)
|
||||
@foreach (var format in FileExportFormat.AnswerFormats)
|
||||
{
|
||||
<MudSelectItem Value="@format">
|
||||
@format.ToName()
|
||||
@format.Name
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudJustifiedText Typo="Typo.body2" Class="mb-3">
|
||||
@(string.Format(T("Each answer is stored as its own file. Those files are named after the document, e.g., the answer for report.pdf is stored as report_result{0}."), this.resultFileFormat.ToFileExtension()))
|
||||
@(string.Format(T("Each answer is stored as its own file. Those files are named after the document, e.g., the answer for report.pdf is stored as report_result{0}."), this.resultFileFormat.FileExtension))
|
||||
</MudJustifiedText>
|
||||
}
|
||||
else
|
||||
@@ -179,7 +179,7 @@ else
|
||||
@foreach (var separator in Enum.GetValues<BatchProcessingCsvSeparator>())
|
||||
{
|
||||
<MudSelectItem Value="@separator">
|
||||
@separator.Name()
|
||||
@separator.Name
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
+1
-1
@@ -244,7 +244,7 @@ public partial class AssistantBatchProcessing
|
||||
/// </remarks>
|
||||
private string CreateResultFileName(string sourceFileName)
|
||||
{
|
||||
var extension = this.resultFileFormat.ToFileExtension();
|
||||
var extension = this.resultFileFormat.FileExtension;
|
||||
var stem = Path.GetFileNameWithoutExtension(sourceFileName);
|
||||
var candidate = $"{stem}{RESULT_FILE_SUFFIX}{extension}";
|
||||
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ public partial class AssistantBatchProcessing
|
||||
// hundreds of times, and starting without it would spend time and tokens on answers we
|
||||
// cannot write anywhere:
|
||||
//
|
||||
if (this.outputMode is BatchProcessingOutputMode.INDIVIDUAL_FILES && this.resultFileFormat.UsesPandoc())
|
||||
if (this.outputMode is BatchProcessingOutputMode.INDIVIDUAL_FILES && this.resultFileFormat.UsesPandoc)
|
||||
{
|
||||
var pandocState = await this.PandocAvailability.EnsureAvailabilityAsync(showSuccessMessage: false, showDialog: true);
|
||||
if (!pandocState.IsAvailable)
|
||||
@@ -270,7 +270,7 @@ public partial class AssistantBatchProcessing
|
||||
//
|
||||
var resultText = this.DisclosureService.AddDisclosureToMarkdown(aiAnswer);
|
||||
var resultFilePath = Path.Join(resolvedOutputDirectory, this.CreateResultFileName(fileResult.FileName));
|
||||
if (this.resultFileFormat.UsesPandoc())
|
||||
if (this.resultFileFormat.UsesPandoc)
|
||||
{
|
||||
//
|
||||
// Pandoc reports a failure instead of throwing, because one document which
|
||||
@@ -283,7 +283,7 @@ public partial class AssistantBatchProcessing
|
||||
}
|
||||
}
|
||||
else
|
||||
await File.WriteAllTextAsync(resultFilePath, resultText, this.resultFileFormat.ToFileEncoding(), CancellationToken.None);
|
||||
await File.WriteAllTextAsync(resultFilePath, resultText, this.resultFileFormat.FileEncoding, CancellationToken.None);
|
||||
|
||||
this.FinishFileResult(fileResult, BatchProcessingFileStatus.DONE, Path.GetFileName(resultFilePath));
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public partial class AssistantBatchProcessing
|
||||
|| this.csvSeparator is not BatchProcessingCsvSeparator.CUSTOM)
|
||||
return null;
|
||||
|
||||
if (!BatchProcessingCsvSeparatorExtensions.IsValidCustomSeparator(separator))
|
||||
if (!BatchProcessingCsvSeparator.IsValidCustomSeparator(separator))
|
||||
return T("Please enter exactly one punctuation or symbol character. Letters, numbers, spaces, quotation marks, and line breaks cannot be used as CSV separators.");
|
||||
|
||||
return null;
|
||||
|
||||
+11
-11
@@ -8,7 +8,7 @@ public static class BatchProcessingCsvSeparatorExtensions
|
||||
|
||||
extension(BatchProcessingCsvSeparator separator)
|
||||
{
|
||||
public string Name() => separator switch
|
||||
public string Name => separator switch
|
||||
{
|
||||
BatchProcessingCsvSeparator.COMMA => TB("Comma (,)"),
|
||||
BatchProcessingCsvSeparator.SEMICOLON => TB("Semicolon (;)"),
|
||||
@@ -25,20 +25,20 @@ public static class BatchProcessingCsvSeparatorExtensions
|
||||
BatchProcessingCsvSeparator.SEMICOLON => ';',
|
||||
BatchProcessingCsvSeparator.PIPE => '|',
|
||||
BatchProcessingCsvSeparator.TAB => '\t',
|
||||
BatchProcessingCsvSeparator.CUSTOM when IsValidCustomSeparator(customSeparator) => customSeparator[0],
|
||||
BatchProcessingCsvSeparator.CUSTOM when BatchProcessingCsvSeparator.IsValidCustomSeparator(customSeparator) => customSeparator[0],
|
||||
|
||||
_ => DEFAULT_SEPARATOR,
|
||||
};
|
||||
}
|
||||
|
||||
internal static bool IsValidCustomSeparator(string separator)
|
||||
{
|
||||
if (string.IsNullOrEmpty(separator) || separator.Length is not 1)
|
||||
return false;
|
||||
internal static bool IsValidCustomSeparator(string customSeparator)
|
||||
{
|
||||
if (string.IsNullOrEmpty(customSeparator) || customSeparator.Length is not 1)
|
||||
return false;
|
||||
|
||||
var character = separator[0];
|
||||
return !char.IsLetterOrDigit(character)
|
||||
&& !char.IsWhiteSpace(character)
|
||||
&& character is not '"' and not '\r' and not '\n';
|
||||
var character = customSeparator[0];
|
||||
return !char.IsLetterOrDigit(character)
|
||||
&& !char.IsWhiteSpace(character)
|
||||
&& character is not '"' and not '\r' and not '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ public static class BatchProcessingOutputModeExtensions
|
||||
|
||||
extension(BatchProcessingOutputMode outputMode)
|
||||
{
|
||||
public string Name() => outputMode switch
|
||||
public string Name => outputMode switch
|
||||
{
|
||||
BatchProcessingOutputMode.INDIVIDUAL_FILES => TB("One file per document"),
|
||||
BatchProcessingOutputMode.TABLE_ONLY => TB("One CSV results table, where each answer becomes one row"),
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ public static class BatchProcessingPromptSourceExtensions
|
||||
|
||||
extension(BatchProcessingPromptSource promptSource)
|
||||
{
|
||||
public string Name() => promptSource switch
|
||||
public string Name => promptSource switch
|
||||
{
|
||||
BatchProcessingPromptSource.FREE_PROMPT => TB("Use a free prompt"),
|
||||
BatchProcessingPromptSource.POLICY => TB("Use a document analysis policy"),
|
||||
|
||||
Reference in new issue
Block a user