Skip to content

.Net: Increase auto-invoke and in-flight tool calling hard-coded limits #6272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -30,11 +30,12 @@ public void EnableKernelFunctionsReturnsCorrectKernelFunctionsInstance()
public void AutoInvokeKernelFunctionsReturnsCorrectKernelFunctionsInstance()
{
// Arrange & Act
const int DefaultMaximumAutoInvokeAttempts = 128;
var behavior = GeminiToolCallBehavior.AutoInvokeKernelFunctions;

// Assert
Assert.IsType<GeminiToolCallBehavior.KernelFunctions>(behavior);
Assert.Equal(5, behavior.MaximumAutoInvokeAttempts);
Assert.Equal(DefaultMaximumAutoInvokeAttempts, behavior.MaximumAutoInvokeAttempts);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal sealed class GeminiChatCompletionClient : ClientBase
/// was invoked with), but we do want to limit it. This limit is arbitrary and can be tweaked in the future and/or made
/// configurable should need arise.
/// </remarks>
private const int MaxInflightAutoInvokes = 5;
private const int MaxInflightAutoInvokes = 128;

/// <summary>Tracking <see cref="AsyncLocal{Int32}"/> for <see cref="MaxInflightAutoInvokes"/>.</summary>
private static readonly AsyncLocal<int> s_inflightAutoInvokes = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class GeminiToolCallBehavior
/// support, where the model can request multiple tools in a single response, it is significantly
/// less likely that this limit is reached, as most of the time only a single request is needed.
/// </remarks>
private const int DefaultMaximumAutoInvokeAttempts = 5;
private const int DefaultMaximumAutoInvokeAttempts = 128;

/// <summary>
/// Gets an instance that will provide all of the <see cref="Kernel"/>'s plugins' function information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal abstract class ClientCore
/// was invoked with), but we do want to limit it. This limit is arbitrary and can be tweaked in the future and/or made
/// configurable should need arise.
/// </remarks>
private const int MaxInflightAutoInvokes = 5;
private const int MaxInflightAutoInvokes = 128;

/// <summary>Singleton tool used when tool call count drops to 0 but we need to supply tools to keep the service happy.</summary>
private static readonly ChatCompletionsFunctionToolDefinition s_nonInvocableFunctionTool = new() { Name = "NonInvocableTool" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class ToolCallBehavior
/// support, where the model can request multiple tools in a single response, it is significantly
/// less likely that this limit is reached, as most of the time only a single request is needed.
/// </remarks>
private const int DefaultMaximumAutoInvokeAttempts = 5;
private const int DefaultMaximumAutoInvokeAttempts = 128;

/// <summary>
/// Gets an instance that will provide all of the <see cref="Kernel"/>'s plugins' function information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public async Task GetChatMessageContentsWithFunctionCallAsync()
public async Task GetChatMessageContentsWithFunctionCallMaximumAutoInvokeAttemptsAsync()
{
// Arrange
const int DefaultMaximumAutoInvokeAttempts = 5;
const int DefaultMaximumAutoInvokeAttempts = 128;
const int AutoInvokeResponsesCount = 6;

int functionCallCount = 0;
Expand Down Expand Up @@ -501,7 +501,7 @@ public async Task GetStreamingChatMessageContentsWithFunctionCallAsync()
public async Task GetStreamingChatMessageContentsWithFunctionCallMaximumAutoInvokeAttemptsAsync()
{
// Arrange
const int DefaultMaximumAutoInvokeAttempts = 5;
const int DefaultMaximumAutoInvokeAttempts = 128;
const int AutoInvokeResponsesCount = 6;

int functionCallCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public void EnableKernelFunctionsReturnsCorrectKernelFunctionsInstance()
public void AutoInvokeKernelFunctionsReturnsCorrectKernelFunctionsInstance()
{
// Arrange & Act
const int DefaultMaximumAutoInvokeAttempts = 128;
var behavior = ToolCallBehavior.AutoInvokeKernelFunctions;

// Assert
Assert.IsType<KernelFunctions>(behavior);
Assert.Equal(5, behavior.MaximumAutoInvokeAttempts);
Assert.Equal(DefaultMaximumAutoInvokeAttempts, behavior.MaximumAutoInvokeAttempts);
}

[Fact]
Expand Down
Loading