diff --git a/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor b/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor index b8e781ef8..3075db2b9 100644 --- a/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor +++ b/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor @@ -200,18 +200,9 @@ else @T("Processing pace") -@if (MinimumDelayIsManaged) -{ - - @(string.Format(TA("Your organization requires a pause of at least {0} seconds between files."), this.ManagedMinimumDelaySeconds)) - -} -else -{ - -} - - + @T("Before the next file starts, AI Studio waits for a random number of whole seconds from this interval. The minimum is always 6 seconds and the maximum is 300 seconds (5 minutes). Restored files and the end of a run do not add another pause.") diff --git a/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.Delay.cs b/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.Delay.cs index 0b1b88769..de1f00de4 100644 --- a/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.Delay.cs +++ b/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.Delay.cs @@ -1,5 +1,5 @@ -using AIStudio.Settings; using AIStudio.Settings.DataModel; +using AIStudio.Tools.Pauses; using Microsoft.AspNetCore.Components; @@ -10,27 +10,40 @@ public partial class AssistantBatchProcessing [Inject] private ThreadSafeRandom Rng { get; init; } = null!; - private static bool MinimumDelayIsManaged => ManagedConfiguration.TryGet(x => x.BatchProcessing, x => x.MinimumDelaySeconds, out var meta) - && meta.ManagedMode is not null; + /// + /// The lower bound of the pause between two files as it stands. + /// + /// + /// A bound which a configuration plugin locks belongs to the organization, so it comes from the + /// settings, whatever this assistant held before, e.g., in a session from before the lock. + /// + private int MinimumDelaySeconds => DataBatchProcessing.IsMinimumPauseLocked + ? this.SettingsManager.ConfigurationData.BatchProcessing.MinimumDelaySeconds + : this.minimumDelaySeconds; - private int ManagedMinimumDelaySeconds => Math.Clamp(this.SettingsManager.ConfigurationData.BatchProcessing.MinimumDelaySeconds, - DataBatchProcessing.MIN_DELAY_SECONDS, - DataBatchProcessing.MAX_DELAY_SECONDS); + /// + /// The upper bound of the pause between two files as it stands, cf. MinimumDelaySeconds. + /// + private int MaximumDelaySeconds => DataBatchProcessing.IsMaximumPauseLocked + ? this.SettingsManager.ConfigurationData.BatchProcessing.MaximumDelaySeconds + : this.maximumDelaySeconds; - private int EffectiveMinimumDelaySeconds => MinimumDelayIsManaged ? this.ManagedMinimumDelaySeconds - : Math.Clamp(this.minimumDelaySeconds, DataBatchProcessing.MIN_DELAY_SECONDS, DataBatchProcessing.MAX_DELAY_SECONDS); - - private (int Minimum, int Maximum) GetEffectiveDelayRange() - { - var minimum = this.EffectiveMinimumDelaySeconds; - var maximum = Math.Clamp(this.maximumDelaySeconds, minimum, DataBatchProcessing.MAX_DELAY_SECONDS); - return (minimum, maximum); - } + /// + /// The bounds of the pause between two files which apply to a run, cf. PauseRange.GetEffective. + /// + private PauseRange EffectivePauseRange => PauseRange.GetEffective( + DataBatchProcessing.PAUSE_LIMITS, + this.MinimumDelaySeconds, + () => DataBatchProcessing.IsMinimumPauseLocked, + this.MaximumDelaySeconds, + () => DataBatchProcessing.IsMaximumPauseLocked); /// /// Waits for a random, inclusive duration before the next file starts. /// - private async Task WaitBeforeNextFileAsync(int minimumSeconds, int maximumSeconds, CancellationToken token) + /// The bounds of the pause, as they apply to the run. + /// Ends the wait when the user stops the run. + private async Task WaitBeforeNextFileAsync(PauseRange range, CancellationToken token) { if (token.IsCancellationRequested) return; @@ -38,12 +51,12 @@ public partial class AssistantBatchProcessing // ThreadSafeRandom is the application-wide singleton. Batch runs must // not create private Random instances because several runs may execute // concurrently in different assistant sessions. - this.pauseBeforeNextFileSeconds = this.Rng.Next(minimumSeconds, maximumSeconds + 1); + this.pauseBeforeNextFileSeconds = this.Rng.Next(range.MinimumSeconds, range.MaximumSeconds + 1); this.Logger.LogInformation("Batch processing waits {DelaySeconds} seconds before starting the next file.", this.pauseBeforeNextFileSeconds); await this.CheckpointAssistantSession(); await this.RefreshAssistantUIAsync(); - + try { await Task.Delay(TimeSpan.FromSeconds(this.pauseBeforeNextFileSeconds), token); diff --git a/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.Run.cs b/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.Run.cs index 84ee299c5..833074b2f 100644 --- a/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.Run.cs +++ b/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.Run.cs @@ -119,7 +119,7 @@ public partial class AssistantBatchProcessing { this.isProcessingBatch = true; var stopwatch = Stopwatch.StartNew(); - var delayRange = this.GetEffectiveDelayRange(); + var pauseRange = this.EffectivePauseRange; this.Logger.LogInformation( "Batch processing started. InputDirectory='{InputDirectory}', OutputDirectory='{OutputDirectory}', TotalFiles={TotalFiles}, RestoredFiles={RestoredFiles}, Model='{Model}', MinimumDelaySeconds={MinimumDelaySeconds}, MaximumDelaySeconds={MaximumDelaySeconds}.", this.inputDirectory, @@ -127,8 +127,8 @@ public partial class AssistantBatchProcessing this.fileResults.Count, this.fileResults.Count(fileResult => fileResult.Status is BatchProcessingFileStatus.DONE), this.ProviderSettings.Model, - delayRange.Minimum, - delayRange.Maximum); + pauseRange.MinimumSeconds, + pauseRange.MaximumSeconds); // We use the cancellation token of the assistant base class, which // creates it before it calls us and disposes it after we returned. @@ -166,7 +166,7 @@ public partial class AssistantBatchProcessing var anotherFileIsWaiting = this.fileResults.Skip(index + 1).Any(nextFile => nextFile.Status is not BatchProcessingFileStatus.DONE); if (anotherFileIsWaiting) - await this.WaitBeforeNextFileAsync(delayRange.Minimum, delayRange.Maximum, token); + await this.WaitBeforeNextFileAsync(pauseRange, token); } } finally diff --git a/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.cs b/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.cs index 52f9db665..1b4141921 100644 --- a/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.cs +++ b/app/MindWork AI Studio/Assistants/BatchProcessing/AssistantBatchProcessing.razor.cs @@ -213,8 +213,8 @@ public partial class AssistantBatchProcessing : AssistantBaseCore