Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ await RenderEvaluationPromptAsync(
{
if (history.Count == 1)
{
bool canRender =
(bool canRender, tokenBudget) =
await CanRenderAsync(
history[0],
ref tokenBudget,
tokenBudget,
chatConfiguration,
cancellationToken).ConfigureAwait(false);

Expand All @@ -132,10 +132,10 @@ await CanRenderAsync(
{
cancellationToken.ThrowIfCancellationRequested();

bool canRender =
(bool canRender, tokenBudget) =
await CanRenderAsync(
message,
ref tokenBudget,
tokenBudget,
chatConfiguration,
cancellationToken).ConfigureAwait(false);

Expand Down Expand Up @@ -222,12 +222,12 @@ await ParseEvaluationResponseAsync(
/// </param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can cancel the operation.</param>
/// <returns>
/// <see langword="true"/> if there is sufficient <paramref name="tokenBudget"/> remaining to render the supplied
/// <paramref name="message"/> as part of the evaluation prompt; <see langword="false"/> otherwise.
/// A tuple containing a boolean indicating if there is sufficient <paramref name="tokenBudget"/> remaining to render the supplied
/// <paramref name="message"/> as part of the evaluation prompt and an int returning the remaining token budget.
/// </returns>
protected virtual ValueTask<bool> CanRenderAsync(
protected virtual ValueTask<(bool tokenBudgetSufficient, int tokenBudgetRemaining)> CanRenderAsync(
ChatMessage message,
ref int tokenBudget,
int tokenBudget,
ChatConfiguration chatConfiguration,
CancellationToken cancellationToken)
{
Expand All @@ -237,7 +237,7 @@ protected virtual ValueTask<bool> CanRenderAsync(
IEvaluationTokenCounter? tokenCounter = chatConfiguration.TokenCounter;
if (tokenCounter is null)
{
return new ValueTask<bool>(true);
return new ValueTask<(bool, int)>((true, tokenBudget));
}

string? author = message.AuthorName;
Expand All @@ -261,12 +261,12 @@ protected virtual ValueTask<bool> CanRenderAsync(

if (tokenCount > tokenBudget)
{
return new ValueTask<bool>(false);
return new ValueTask<(bool, int)>((false, tokenBudget));
}
else
{
tokenBudget -= tokenCount;
return new ValueTask<bool>(true);
return new ValueTask<(bool, int)>((true, tokenBudget));
}
}

Expand Down