Skip to content

Commit

Permalink
.Net: Increase auto-invoke and in-flight tool calling hard-coded limi…
Browse files Browse the repository at this point in the history
…ts (#6272)

As we discussed offline yesterday, with auto function calling filters,
someone can now put their own limits in place, so raising these
hard-coded back stops to something much less likely to be hit. We could
subsequently get rid of them completely if desired.

---------

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
Co-authored-by: SergeyMenshykh <sergemenshikh@gmail.com>
  • Loading branch information
3 people committed May 16, 2024
1 parent 08bcc80 commit 41f072d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
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,8 +323,8 @@ public async Task GetChatMessageContentsWithFunctionCallAsync()
public async Task GetChatMessageContentsWithFunctionCallMaximumAutoInvokeAttemptsAsync()
{
// Arrange
const int DefaultMaximumAutoInvokeAttempts = 5;
const int AutoInvokeResponsesCount = 6;
const int DefaultMaximumAutoInvokeAttempts = 128;
const int ModelResponsesCount = 129;

int functionCallCount = 0;

Expand All @@ -342,7 +342,7 @@ public async Task GetChatMessageContentsWithFunctionCallMaximumAutoInvokeAttempt

var responses = new List<HttpResponseMessage>();

for (var i = 0; i < AutoInvokeResponsesCount; i++)
for (var i = 0; i < ModelResponsesCount; i++)
{
responses.Add(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(OpenAITestHelper.GetTestResponse("chat_completion_single_function_call_test_response.json")) });
}
Expand Down Expand Up @@ -501,8 +501,8 @@ public async Task GetStreamingChatMessageContentsWithFunctionCallAsync()
public async Task GetStreamingChatMessageContentsWithFunctionCallMaximumAutoInvokeAttemptsAsync()
{
// Arrange
const int DefaultMaximumAutoInvokeAttempts = 5;
const int AutoInvokeResponsesCount = 6;
const int DefaultMaximumAutoInvokeAttempts = 128;
const int ModelResponsesCount = 129;

int functionCallCount = 0;

Expand All @@ -520,7 +520,7 @@ public async Task GetStreamingChatMessageContentsWithFunctionCallMaximumAutoInvo

var responses = new List<HttpResponseMessage>();

for (var i = 0; i < AutoInvokeResponsesCount; i++)
for (var i = 0; i < ModelResponsesCount; i++)
{
responses.Add(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(OpenAITestHelper.GetTestResponse("chat_completion_streaming_single_function_call_test_response.txt")) });
}
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

0 comments on commit 41f072d

Please sign in to comment.