From c9539c10a0c6fb92679b0897c376b2fc3e7313f2 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 20 Nov 2024 12:30:41 -0500 Subject: [PATCH] chore: avoid awaiting delay if its zero Signed-off-by: Vincent Biret --- .../Orchestration.Flow/Execution/FlowExecutor.cs | 12 +++++++++--- .../Stepwise/FunctionCallingStepwisePlanner.cs | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dotnet/src/Experimental/Orchestration.Flow/Execution/FlowExecutor.cs b/dotnet/src/Experimental/Orchestration.Flow/Execution/FlowExecutor.cs index b59bc6baa183..58fbe9d010e0 100644 --- a/dotnet/src/Experimental/Orchestration.Flow/Execution/FlowExecutor.cs +++ b/dotnet/src/Experimental/Orchestration.Flow/Execution/FlowExecutor.cs @@ -679,7 +679,10 @@ private async Task ExecuteStepAsync(FlowStep step, string sessio string? actionResult; try { - await Task.Delay(this._config.MinIterationTimeMs).ConfigureAwait(false); + if (this._config.MinIterationTimeMs > 0) + { + await Task.Delay(this._config.MinIterationTimeMs).ConfigureAwait(false); + } actionResult = await this._reActEngine.InvokeActionAsync(actionStep, input, chatHistory, kernel, actionContextVariables).ConfigureAwait(false); if (string.IsNullOrEmpty(actionResult)) @@ -776,8 +779,11 @@ private async Task ExecuteStepAsync(FlowStep step, string sessio this._logger?.LogWarning("Action: No action to take"); } - // continue to next iteration - await Task.Delay(this._config.MinIterationTimeMs).ConfigureAwait(false); + if (this._config.MinIterationTimeMs > 0) + { + // continue to next iteration + await Task.Delay(this._config.MinIterationTimeMs).ConfigureAwait(false); + } } throw new KernelException($"Failed to complete step {stepId} for session {sessionId}."); diff --git a/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs b/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs index fe31efb14bae..7b0a39b845f0 100644 --- a/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs +++ b/dotnet/src/Planners/Planners.OpenAI/Stepwise/FunctionCallingStepwisePlanner.cs @@ -88,7 +88,7 @@ private async Task ExecuteCoreAsync( for (int i = 0; i < this._options.MaxIterations; i++) { // sleep for a bit to avoid rate limiting - if (i > 0) + if (i > 0 && this._options.MinIterationTimeMs > 0) { await Task.Delay(this._options.MinIterationTimeMs, cancellationToken).ConfigureAwait(false); }