Skip to content

Commit

Permalink
chore: avoid awaiting delay if its zero
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Nov 20, 2024
1 parent f5facce commit c9539c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,10 @@ private async Task<FunctionResult> 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))
Expand Down Expand Up @@ -776,8 +779,11 @@ private async Task<FunctionResult> 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}.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private async Task<FunctionCallingStepwisePlannerResult> 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);
}
Expand Down

0 comments on commit c9539c1

Please sign in to comment.