From 0ebd8ce2424d61db161898e1a583b70c4c3b767f Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 11 Feb 2025 10:49:51 -0500 Subject: [PATCH] Fix up a few more stale references to Complete{Streaming}Async (mainly tests) --- .../AnonymousDelegatingChatClient.cs | 4 +-- .../ChatClientExtensionsTests.cs | 12 ++++---- .../DelegatingChatClientTests.cs | 4 +-- .../TestChatClient.cs | 8 +++--- .../ChatClientIntegrationTests.cs | 28 +++++++++---------- .../ReducingChatClientTests.cs | 2 +- ...atClientStructuredOutputExtensionsTests.cs | 20 ++++++------- .../ConfigureOptionsChatClientTests.cs | 4 +-- .../DistributedCachingChatClientTest.cs | 28 +++++++++---------- .../FunctionInvokingChatClientTests.cs | 14 +++++----- .../ChatCompletion/LoggingChatClientTests.cs | 4 +-- .../OpenTelemetryChatClientTests.cs | 4 +-- .../UseDelegateChatClientTests.cs | 12 ++++---- 13 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/AnonymousDelegatingChatClient.cs b/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/AnonymousDelegatingChatClient.cs index 9a533363270..bfc113a939b 100644 --- a/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/AnonymousDelegatingChatClient.cs +++ b/src/Libraries/Microsoft.Extensions.AI/ChatCompletion/AnonymousDelegatingChatClient.cs @@ -164,9 +164,9 @@ await _sharedFunc(chatMessages, options, async (chatMessages, options, cancellat else { Debug.Assert(_getResponseFunc is not null, "Expected non-null non-streaming delegate."); - return CompleteStreamingAsyncViaCompleteAsync(_getResponseFunc!(chatMessages, options, InnerClient, cancellationToken)); + return GetStreamingResponseAsyncViaGetResponseAsync(_getResponseFunc!(chatMessages, options, InnerClient, cancellationToken)); - static async IAsyncEnumerable CompleteStreamingAsyncViaCompleteAsync(Task task) + static async IAsyncEnumerable GetStreamingResponseAsyncViaGetResponseAsync(Task task) { ChatResponse response = await task.ConfigureAwait(false); foreach (var update in response.ToChatResponseUpdates()) diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatClientExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatClientExtensionsTests.cs index 8ca61022255..64ea4406be9 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatClientExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatClientExtensionsTests.cs @@ -18,7 +18,7 @@ public void GetService_InvalidArgs_Throws() } [Fact] - public void CompleteAsync_InvalidArgs_Throws() + public void GetResponseAsync_InvalidArgs_Throws() { Assert.Throws("client", () => { @@ -32,7 +32,7 @@ public void CompleteAsync_InvalidArgs_Throws() } [Fact] - public void CompleteStreamingAsync_InvalidArgs_Throws() + public void GetStreamingResponseAsync_InvalidArgs_Throws() { Assert.Throws("client", () => { @@ -46,7 +46,7 @@ public void CompleteStreamingAsync_InvalidArgs_Throws() } [Fact] - public async Task CompleteAsync_CreatesTextMessageAsync() + public async Task GetResponseAsync_CreatesTextMessageAsync() { var expectedResponse = new ChatResponse([new ChatMessage()]); var expectedOptions = new ChatOptions(); @@ -54,7 +54,7 @@ public async Task CompleteAsync_CreatesTextMessageAsync() using TestChatClient client = new() { - CompleteAsyncCallback = (chatMessages, options, cancellationToken) => + GetResponseAsyncCallback = (chatMessages, options, cancellationToken) => { ChatMessage m = Assert.Single(chatMessages); Assert.Equal(ChatRole.User, m.Role); @@ -74,14 +74,14 @@ public async Task CompleteAsync_CreatesTextMessageAsync() } [Fact] - public async Task CompleteStreamingAsync_CreatesTextMessageAsync() + public async Task GetStreamingResponseAsync_CreatesTextMessageAsync() { var expectedOptions = new ChatOptions(); using var cts = new CancellationTokenSource(); using TestChatClient client = new() { - CompleteStreamingAsyncCallback = (chatMessages, options, cancellationToken) => + GetStreamingResponseAsyncCallback = (chatMessages, options, cancellationToken) => { ChatMessage m = Assert.Single(chatMessages); Assert.Equal(ChatRole.User, m.Role); diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/DelegatingChatClientTests.cs b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/DelegatingChatClientTests.cs index d408f8e5fd1..d7d265018b0 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/DelegatingChatClientTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/DelegatingChatClientTests.cs @@ -28,7 +28,7 @@ public async Task ChatAsyncDefaultsToInnerClientAsync() var expectedResponse = new ChatResponse([]); using var inner = new TestChatClient { - CompleteAsyncCallback = (chatContents, options, cancellationToken) => + GetResponseAsyncCallback = (chatContents, options, cancellationToken) => { Assert.Same(expectedChatContents, chatContents); Assert.Same(expectedChatOptions, options); @@ -64,7 +64,7 @@ public async Task ChatStreamingAsyncDefaultsToInnerClientAsync() using var inner = new TestChatClient { - CompleteStreamingAsyncCallback = (chatContents, options, cancellationToken) => + GetStreamingResponseAsyncCallback = (chatContents, options, cancellationToken) => { Assert.Same(expectedChatContents, chatContents); Assert.Same(expectedChatOptions, options); diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/TestChatClient.cs b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/TestChatClient.cs index 1bb147bb24e..226612bcff4 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/TestChatClient.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/TestChatClient.cs @@ -17,9 +17,9 @@ public TestChatClient() public IServiceProvider? Services { get; set; } - public Func, ChatOptions?, CancellationToken, Task>? CompleteAsyncCallback { get; set; } + public Func, ChatOptions?, CancellationToken, Task>? GetResponseAsyncCallback { get; set; } - public Func, ChatOptions?, CancellationToken, IAsyncEnumerable>? CompleteStreamingAsyncCallback { get; set; } + public Func, ChatOptions?, CancellationToken, IAsyncEnumerable>? GetStreamingResponseAsyncCallback { get; set; } public Func GetServiceCallback { get; set; } @@ -27,10 +27,10 @@ public TestChatClient() serviceType is not null && serviceKey is null && serviceType.IsInstanceOfType(this) ? this : null; public Task GetResponseAsync(IList chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) - => CompleteAsyncCallback!.Invoke(chatMessages, options, cancellationToken); + => GetResponseAsyncCallback!.Invoke(chatMessages, options, cancellationToken); public IAsyncEnumerable GetStreamingResponseAsync(IList chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default) - => CompleteStreamingAsyncCallback!.Invoke(chatMessages, options, cancellationToken); + => GetStreamingResponseAsyncCallback!.Invoke(chatMessages, options, cancellationToken); public object? GetService(Type serviceType, object? serviceKey = null) => GetServiceCallback(serviceType, serviceKey); diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs index 166cb51e930..1ba067f6d2f 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs @@ -42,7 +42,7 @@ public void Dispose() protected abstract IChatClient? CreateChatClient(); [ConditionalFact] - public virtual async Task CompleteAsync_SingleRequestMessage() + public virtual async Task GetResponseAsync_SingleRequestMessage() { SkipIfNotEnabled(); @@ -52,7 +52,7 @@ public virtual async Task CompleteAsync_SingleRequestMessage() } [ConditionalFact] - public virtual async Task CompleteAsync_MultipleRequestMessages() + public virtual async Task GetResponseAsync_MultipleRequestMessages() { SkipIfNotEnabled(); @@ -71,7 +71,7 @@ public virtual async Task CompleteAsync_MultipleRequestMessages() } [ConditionalFact] - public virtual async Task CompleteStreamingAsync_SingleStreamingResponseChoice() + public virtual async Task GetStreamingResponseAsync_SingleStreamingResponseChoice() { SkipIfNotEnabled(); @@ -95,7 +95,7 @@ public virtual async Task CompleteStreamingAsync_SingleStreamingResponseChoice() } [ConditionalFact] - public virtual async Task CompleteAsync_UsageDataAvailable() + public virtual async Task GetResponseAsync_UsageDataAvailable() { SkipIfNotEnabled(); @@ -108,7 +108,7 @@ public virtual async Task CompleteAsync_UsageDataAvailable() } [ConditionalFact] - public virtual async Task CompleteStreamingAsync_UsageDataAvailable() + public virtual async Task GetStreamingResponseAsync_UsageDataAvailable() { SkipIfNotEnabled(); @@ -631,7 +631,7 @@ public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics() } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutput() + public virtual async Task GetResponseAsync_StructuredOutput() { SkipIfNotEnabled(); @@ -647,7 +647,7 @@ Who is described in the following sentence? } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutputArray() + public virtual async Task GetResponseAsync_StructuredOutputArray() { SkipIfNotEnabled(); @@ -663,7 +663,7 @@ Who are described in the following sentence? } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutputInteger() + public virtual async Task GetResponseAsync_StructuredOutputInteger() { SkipIfNotEnabled(); @@ -676,7 +676,7 @@ To fix this we added another one. How many are there now? } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutputString() + public virtual async Task GetResponseAsync_StructuredOutputString() { SkipIfNotEnabled(); @@ -689,7 +689,7 @@ public virtual async Task CompleteAsync_StructuredOutputString() } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutputBool_True() + public virtual async Task GetResponseAsync_StructuredOutputBool_True() { SkipIfNotEnabled(); @@ -702,7 +702,7 @@ Is there at least one software developer from Cardiff? } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutputBool_False() + public virtual async Task GetResponseAsync_StructuredOutputBool_False() { SkipIfNotEnabled(); @@ -715,7 +715,7 @@ Can we be sure that he is a medical doctor? } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutputEnum() + public virtual async Task GetResponseAsync_StructuredOutputEnum() { SkipIfNotEnabled(); @@ -727,7 +727,7 @@ Taylor Swift is a famous singer and songwriter. What is her job? } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutput_WithFunctions() + public virtual async Task GetResponseAsync_StructuredOutput_WithFunctions() { SkipIfNotEnabled(); @@ -758,7 +758,7 @@ public virtual async Task CompleteAsync_StructuredOutput_WithFunctions() } [ConditionalFact] - public virtual async Task CompleteAsync_StructuredOutput_Native() + public virtual async Task GetResponseAsync_StructuredOutput_Native() { SkipIfNotEnabled(); diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ReducingChatClientTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ReducingChatClientTests.cs index b736d3524b6..eeccd609a93 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ReducingChatClientTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ReducingChatClientTests.cs @@ -27,7 +27,7 @@ public async Task Reduction_LimitsMessagesBasedOnTokenLimit() { using var innerClient = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { Assert.Equal(2, messages.Count); Assert.Collection(messages, diff --git a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs index a2c7d623f00..a825ae5a46a 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs @@ -28,7 +28,7 @@ public async Task SuccessUsage() using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { var responseFormat = Assert.IsType(options!.ResponseFormat); Assert.Null(responseFormat.Schema); @@ -82,7 +82,7 @@ public async Task WrapsNonObjectValuesInDataProperty() using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { var suppliedSchemaMatch = Regex.Match(messages[1].Text!, "```(.*?)```", RegexOptions.Singleline); Assert.True(suppliedSchemaMatch.Success); @@ -113,7 +113,7 @@ public async Task FailureUsage_InvalidJson() var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "This is not valid JSON")); using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse), + GetResponseAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse), }; var chatHistory = new List { new(ChatRole.User, "Hello") }; @@ -132,7 +132,7 @@ public async Task FailureUsage_NullJson() var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "null")); using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse), + GetResponseAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse), }; var chatHistory = new List { new(ChatRole.User, "Hello") }; @@ -151,7 +151,7 @@ public async Task FailureUsage_NoJsonInResponse() var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, [new DataContent("https://example.com")])); using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse), + GetResponseAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse), }; var chatHistory = new List { new(ChatRole.User, "Hello") }; @@ -172,7 +172,7 @@ public async Task CanUseNativeStructuredOutput() using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { var responseFormat = Assert.IsType(options!.ResponseFormat); Assert.Equal(nameof(Animal), responseFormat.SchemaName); @@ -216,7 +216,7 @@ public async Task CanUseNativeStructuredOutputWithSanitizedTypeName() using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { var responseFormat = Assert.IsType(options!.ResponseFormat); @@ -251,7 +251,7 @@ public async Task CanUseNativeStructuredOutputWithArray() using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse) + GetResponseAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse) }; var chatHistory = new List { new(ChatRole.User, "Hello") }; @@ -282,7 +282,7 @@ public async Task CanSpecifyCustomJsonSerializationOptions() using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { Assert.Collection(messages, message => Assert.Equal("Hello", message.Text), @@ -322,7 +322,7 @@ public async Task HandlesBackendReturningMultipleObjects() using var client = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, resultDuplicatedJson))); }, diff --git a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ConfigureOptionsChatClientTests.cs b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ConfigureOptionsChatClientTests.cs index 77e6b6bf653..d1ae1c21ebe 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ConfigureOptionsChatClientTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ConfigureOptionsChatClientTests.cs @@ -40,14 +40,14 @@ public async Task ConfigureOptions_ReturnedInstancePassedToNextClient(bool nullP using IChatClient innerClient = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { Assert.Same(returnedOptions, options); Assert.Equal(cts.Token, cancellationToken); return Task.FromResult(expectedResponse); }, - CompleteStreamingAsyncCallback = (messages, options, cancellationToken) => + GetStreamingResponseAsyncCallback = (messages, options, cancellationToken) => { Assert.Same(returnedOptions, options); Assert.Equal(cts.Token, cancellationToken); diff --git a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/DistributedCachingChatClientTest.cs b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/DistributedCachingChatClientTest.cs index 8ec8546d16b..b87b866c50f 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/DistributedCachingChatClientTest.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/DistributedCachingChatClientTest.cs @@ -71,7 +71,7 @@ public async Task CachesSuccessResultsAsync() var innerCallCount = 0; using var testClient = new TestChatClient { - CompleteAsyncCallback = delegate + GetResponseAsyncCallback = delegate { innerCallCount++; return Task.FromResult(expectedResponse); @@ -107,7 +107,7 @@ public async Task AllowsConcurrentCallsAsync() var completionTcs = new TaskCompletionSource(); using var testClient = new TestChatClient { - CompleteAsyncCallback = async delegate + GetResponseAsyncCallback = async delegate { innerCallCount++; await completionTcs.Task; @@ -144,7 +144,7 @@ public async Task DoesNotCacheExceptionResultsAsync() var innerCallCount = 0; using var testClient = new TestChatClient { - CompleteAsyncCallback = delegate + GetResponseAsyncCallback = delegate { innerCallCount++; throw new InvalidTimeZoneException("some failure"); @@ -177,7 +177,7 @@ public async Task DoesNotCacheCanceledResultsAsync() var resolutionTcs = new TaskCompletionSource(); using var testClient = new TestChatClient { - CompleteAsyncCallback = async delegate + GetResponseAsyncCallback = async delegate { innerCallCount++; if (innerCallCount == 1) @@ -258,7 +258,7 @@ public async Task StreamingCachesSuccessResultsAsync() var innerCallCount = 0; using var testClient = new TestChatClient { - CompleteStreamingAsyncCallback = delegate + GetStreamingResponseAsyncCallback = delegate { innerCallCount++; return ToAsyncEnumerableAsync(actualUpdate); @@ -305,7 +305,7 @@ public async Task StreamingCoalescesConsecutiveTextChunksAsync(bool? coalesce) using var testClient = new TestChatClient { - CompleteStreamingAsyncCallback = delegate { return ToAsyncEnumerableAsync(expectedResponse); } + GetStreamingResponseAsyncCallback = delegate { return ToAsyncEnumerableAsync(expectedResponse); } }; using var outer = new DistributedCachingChatClient(testClient, _storage) { @@ -382,7 +382,7 @@ public async Task StreamingCoalescingPropagatesMetadataAsync() using var testClient = new TestChatClient { - CompleteStreamingAsyncCallback = delegate { return ToAsyncEnumerableAsync(expectedResponse); } + GetStreamingResponseAsyncCallback = delegate { return ToAsyncEnumerableAsync(expectedResponse); } }; using var outer = new DistributedCachingChatClient(testClient, _storage) { @@ -420,7 +420,7 @@ public async Task StreamingAllowsConcurrentCallsAsync() ]; using var testClient = new TestChatClient { - CompleteStreamingAsyncCallback = delegate + GetStreamingResponseAsyncCallback = delegate { innerCallCount++; return ToAsyncEnumerableAsync(completionTcs.Task, expectedResponse); @@ -459,7 +459,7 @@ public async Task StreamingDoesNotCacheExceptionResultsAsync() var innerCallCount = 0; using var testClient = new TestChatClient { - CompleteStreamingAsyncCallback = delegate + GetStreamingResponseAsyncCallback = delegate { innerCallCount++; return ToAsyncEnumerableAsync(Task.CompletedTask, @@ -498,7 +498,7 @@ public async Task StreamingDoesNotCacheCanceledResultsAsync() var completionTcs = new TaskCompletionSource(); using var testClient = new TestChatClient { - CompleteStreamingAsyncCallback = delegate + GetStreamingResponseAsyncCallback = delegate { innerCallCount++; return ToAsyncEnumerableAsync( @@ -535,7 +535,7 @@ public async Task CacheKeyVariesByChatOptionsAsync() var completionTcs = new TaskCompletionSource(); using var testClient = new TestChatClient { - CompleteAsyncCallback = async (_, options, _) => + GetResponseAsyncCallback = async (_, options, _) => { innerCallCount++; await Task.Yield(); @@ -586,7 +586,7 @@ public async Task SubclassCanOverrideCacheKeyToVaryByChatOptionsAsync() var completionTcs = new TaskCompletionSource(); using var testClient = new TestChatClient { - CompleteAsyncCallback = async (_, options, _) => + GetResponseAsyncCallback = async (_, options, _) => { innerCallCount++; await Task.Yield(); @@ -642,7 +642,7 @@ public async Task CanCacheCustomContentTypesAsync() var innerCallCount = 0; using var testClient = new TestChatClient { - CompleteAsyncCallback = delegate + GetResponseAsyncCallback = delegate { innerCallCount++; return Task.FromResult(expectedResponse); @@ -676,7 +676,7 @@ public async Task CanResolveIDistributedCacheFromDI() .BuildServiceProvider(); using var testClient = new TestChatClient { - CompleteAsyncCallback = delegate + GetResponseAsyncCallback = delegate { return Task.FromResult(new ChatResponse([ new(ChatRole.Assistant, [new TextContent("Hey")])])); diff --git a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs index daaf13040ba..72b2ca93ed8 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs @@ -369,12 +369,12 @@ public async Task RejectsMultipleChoicesAsync() using var innerClient = new TestChatClient { - CompleteAsyncCallback = async (chatContents, options, cancellationToken) => + GetResponseAsyncCallback = async (chatContents, options, cancellationToken) => { await Task.Yield(); return expected; }, - CompleteStreamingAsyncCallback = (chatContents, options, cancellationToken) => + GetStreamingResponseAsyncCallback = (chatContents, options, cancellationToken) => YieldAsync(expected.ToChatResponseUpdates()), }; @@ -529,7 +529,7 @@ public async Task SupportsConsecutiveStreamingUpdatesWithFunctionCalls() using var innerClient = new TestChatClient { - CompleteStreamingAsyncCallback = (chatContents, chatOptions, cancellationToken) => + GetStreamingResponseAsyncCallback = (chatContents, chatOptions, cancellationToken) => { // If the conversation is just starting, issue two consecutive updates with function calls // Otherwise just end the conversation @@ -689,9 +689,9 @@ public async Task PropagatesResponseChatThreadIdToOptions() using var innerClient = new TestChatClient { - CompleteAsyncCallback = (chatContents, chatOptions, cancellationToken) => + GetResponseAsyncCallback = (chatContents, chatOptions, cancellationToken) => Task.FromResult(callback(chatContents, chatOptions, cancellationToken)), - CompleteStreamingAsyncCallback = (chatContents, chatOptions, cancellationToken) => + GetStreamingResponseAsyncCallback = (chatContents, chatOptions, cancellationToken) => YieldAsync(callback(chatContents, chatOptions, cancellationToken).ToChatResponseUpdates()), }; @@ -720,7 +720,7 @@ private static async Task> InvokeAndAssertAsync( using var innerClient = new TestChatClient { - CompleteAsyncCallback = async (contents, actualOptions, actualCancellationToken) => + GetResponseAsyncCallback = async (contents, actualOptions, actualCancellationToken) => { Assert.Equal(cts.Token, actualCancellationToken); @@ -813,7 +813,7 @@ private static async Task> InvokeAndAssertStreamingAsync( using var innerClient = new TestChatClient { - CompleteStreamingAsyncCallback = (contents, actualOptions, actualCancellationToken) => + GetStreamingResponseAsyncCallback = (contents, actualOptions, actualCancellationToken) => { Assert.Equal(cts.Token, actualCancellationToken); diff --git a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/LoggingChatClientTests.cs b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/LoggingChatClientTests.cs index 9d50246826c..721768a5e08 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/LoggingChatClientTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/LoggingChatClientTests.cs @@ -54,7 +54,7 @@ public async Task GetResponseAsync_LogsResponseInvocationAndCompletion(LogLevel using IChatClient innerClient = new TestChatClient { - CompleteAsyncCallback = (messages, options, cancellationToken) => + GetResponseAsyncCallback = (messages, options, cancellationToken) => { return Task.FromResult(new ChatResponse([new(ChatRole.Assistant, "blue whale")])); }, @@ -99,7 +99,7 @@ public async Task GetResponseStreamingStreamAsync_LogsUpdateReceived(LogLevel le using IChatClient innerClient = new TestChatClient { - CompleteStreamingAsyncCallback = (messages, options, cancellationToken) => GetUpdatesAsync() + GetStreamingResponseAsyncCallback = (messages, options, cancellationToken) => GetUpdatesAsync() }; static async IAsyncEnumerable GetUpdatesAsync() diff --git a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs index 3849b04778a..bccba4cc65d 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs @@ -35,7 +35,7 @@ public async Task ExpectedInformationLogged_Async(bool enableSensitiveData, bool using var innerClient = new TestChatClient { - CompleteAsyncCallback = async (messages, options, cancellationToken) => + GetResponseAsyncCallback = async (messages, options, cancellationToken) => { await Task.Yield(); return new ChatResponse(new ChatMessage(ChatRole.Assistant, "The blue whale, I think.")) @@ -55,7 +55,7 @@ public async Task ExpectedInformationLogged_Async(bool enableSensitiveData, bool }, }; }, - CompleteStreamingAsyncCallback = CallbackAsync, + GetStreamingResponseAsyncCallback = CallbackAsync, GetServiceCallback = (serviceType, serviceKey) => serviceType == typeof(ChatClientMetadata) ? new ChatClientMetadata("testservice", new Uri("http://localhost:12345/something"), "amazingmodel") : null, diff --git a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/UseDelegateChatClientTests.cs b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/UseDelegateChatClientTests.cs index e1221a76210..093a2462056 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/UseDelegateChatClientTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/UseDelegateChatClientTests.cs @@ -41,7 +41,7 @@ public async Task Shared_ContextPropagated() using IChatClient innerClient = new TestChatClient { - CompleteAsyncCallback = (chatMessages, options, cancellationToken) => + GetResponseAsyncCallback = (chatMessages, options, cancellationToken) => { Assert.Same(expectedMessages, chatMessages); Assert.Same(expectedOptions, options); @@ -50,7 +50,7 @@ public async Task Shared_ContextPropagated() return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "hello"))); }, - CompleteStreamingAsyncCallback = (chatMessages, options, cancellationToken) => + GetStreamingResponseAsyncCallback = (chatMessages, options, cancellationToken) => { Assert.Same(expectedMessages, chatMessages); Assert.Same(expectedOptions, options); @@ -90,7 +90,7 @@ public async Task CompleteFunc_ContextPropagated() using IChatClient innerClient = new TestChatClient { - CompleteAsyncCallback = (chatMessages, options, cancellationToken) => + GetResponseAsyncCallback = (chatMessages, options, cancellationToken) => { Assert.Same(expectedMessages, chatMessages); Assert.Same(expectedOptions, options); @@ -132,7 +132,7 @@ public async Task CompleteStreamingFunc_ContextPropagated() using IChatClient innerClient = new TestChatClient { - CompleteStreamingAsyncCallback = (chatMessages, options, cancellationToken) => + GetStreamingResponseAsyncCallback = (chatMessages, options, cancellationToken) => { Assert.Same(expectedMessages, chatMessages); Assert.Same(expectedOptions, options); @@ -183,7 +183,7 @@ public async Task BothCompleteAndCompleteStreamingFuncs_ContextPropagated() using IChatClient innerClient = new TestChatClient { - CompleteAsyncCallback = (chatMessages, options, cancellationToken) => + GetResponseAsyncCallback = (chatMessages, options, cancellationToken) => { Assert.Same(expectedMessages, chatMessages); Assert.Same(expectedOptions, options); @@ -192,7 +192,7 @@ public async Task BothCompleteAndCompleteStreamingFuncs_ContextPropagated() return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, "non-streaming hello"))); }, - CompleteStreamingAsyncCallback = (chatMessages, options, cancellationToken) => + GetStreamingResponseAsyncCallback = (chatMessages, options, cancellationToken) => { Assert.Same(expectedMessages, chatMessages); Assert.Same(expectedOptions, options);