Skip to content
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

Flip default on FunctionInvokingChatClient.ConcurrentInvocation #5485

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -82,15 +82,14 @@ public FunctionInvokingChatClient(IChatClient innerClient)
/// <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
/// true to enable concurrent invocation such that multiple function calls may execute in parallel.
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
/// </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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -71,7 +84,7 @@ await InvokeAndAssertAsync(options, [
}

[Fact]
public async Task ParallelFunctionCallsInvokedConcurrentlyByDefaultAsync()
public async Task ParallelFunctionCallsMayBeInvokedConcurrentlyAsync()
{
using var barrier = new Barrier(2);

Expand All @@ -97,11 +110,11 @@ await InvokeAndAssertAsync(options, [
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;

Expand Down Expand Up @@ -130,7 +143,7 @@ await InvokeAndAssertAsync(options, [
new FunctionResultContent("callId2", "Func", result: "worldworld"),
]),
new ChatMessage(ChatRole.Assistant, "done"),
], configurePipeline: b => b.Use(s => new FunctionInvokingChatClient(s) { ConcurrentInvocation = false }));
]);
}

[Theory]
Expand Down
Loading