Flip default on FunctionInvokingChatClient.ConcurrentInvocation (#5485)

* Flip default on FunctionInvokingChatClient.ConcurrentInvocation

For better reliability, default ConcurrentInvocation to false, so that it doesn't introduce concurrency / parallelism where there wasn't any.

* Update src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs

Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>

---------

Co-authored-by: Igor Velikorossov <RussKie@users.noreply.github.com>
This commit is contained in:
Stephen Toub 2024-10-09 06:54:43 -04:00 коммит произвёл GitHub
Родитель 331ddb5bb5
Коммит 0c8bc3ea38
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 21 добавлений и 9 удалений

Просмотреть файл

@ -82,15 +82,14 @@ public class FunctionInvokingChatClient : DelegatingChatClient
/// <remarks>
/// <para>
/// An individual response from the inner client may contain multiple function call requests.
/// By default, such function calls may be issued to execute concurrently with each other. Set
/// <see cref="ConcurrentInvocation"/> to false to disable such concurrent invocation and force
/// the functions to be invoked serially.
/// By default, such function calls are processed serially. Set <see cref="ConcurrentInvocation"/> to
/// <see langword="true"/> to enable concurrent invocation such that multiple function calls may execute in parallel.
/// </para>
/// <para>
/// The default value is <see langword="true"/>.
/// The default value is <see langword="false"/>.
/// </para>
/// </remarks>
public bool ConcurrentInvocation { get; set; } = true;
public bool ConcurrentInvocation { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to keep intermediate messages in the chat history.

Просмотреть файл

@ -12,6 +12,19 @@ namespace Microsoft.Extensions.AI;
public class FunctionInvokingChatClientTests
{
[Fact]
public void Ctor_HasExpectedDefaults()
{
using TestChatClient innerClient = new();
using FunctionInvokingChatClient client = new(innerClient);
Assert.False(client.ConcurrentInvocation);
Assert.False(client.DetailedErrors);
Assert.True(client.KeepFunctionCallingMessages);
Assert.Null(client.MaximumIterationsPerRequest);
Assert.False(client.RetryOnError);
}
[Fact]
public async Task SupportsSingleFunctionCallPerRequestAsync()
{
@ -71,7 +84,7 @@ public class FunctionInvokingChatClientTests
}
[Fact]
public async Task ParallelFunctionCallsInvokedConcurrentlyByDefaultAsync()
public async Task ParallelFunctionCallsMayBeInvokedConcurrentlyAsync()
{
using var barrier = new Barrier(2);
@ -97,11 +110,11 @@ public class FunctionInvokingChatClientTests
new FunctionResultContent("callId2", "Func", result: "worldworld"),
]),
new ChatMessage(ChatRole.Assistant, "done"),
]);
], configurePipeline: b => b.Use(s => new FunctionInvokingChatClient(s) { ConcurrentInvocation = true }));
}
[Fact]
public async Task ConcurrentInvocationOfParallelCallsCanBeDisabledAsync()
public async Task ConcurrentInvocationOfParallelCallsDisabledByDefaultAsync()
{
int activeCount = 0;
@ -130,7 +143,7 @@ public class FunctionInvokingChatClientTests
new FunctionResultContent("callId2", "Func", result: "worldworld"),
]),
new ChatMessage(ChatRole.Assistant, "done"),
], configurePipeline: b => b.Use(s => new FunctionInvokingChatClient(s) { ConcurrentInvocation = false }));
]);
}
[Theory]