Skip to content

Commit 131d30b

Browse files
authored
Fix up a few more stale references to Complete{Streaming}Async (mainly tests) (#5876)
1 parent fab3675 commit 131d30b

File tree

13 files changed

+72
-72
lines changed

13 files changed

+72
-72
lines changed

src/Libraries/Microsoft.Extensions.AI/ChatCompletion/AnonymousDelegatingChatClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ await _sharedFunc(chatMessages, options, async (chatMessages, options, cancellat
164164
else
165165
{
166166
Debug.Assert(_getResponseFunc is not null, "Expected non-null non-streaming delegate.");
167-
return CompleteStreamingAsyncViaCompleteAsync(_getResponseFunc!(chatMessages, options, InnerClient, cancellationToken));
167+
return GetStreamingResponseAsyncViaGetResponseAsync(_getResponseFunc!(chatMessages, options, InnerClient, cancellationToken));
168168

169-
static async IAsyncEnumerable<ChatResponseUpdate> CompleteStreamingAsyncViaCompleteAsync(Task<ChatResponse> task)
169+
static async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsyncViaGetResponseAsync(Task<ChatResponse> task)
170170
{
171171
ChatResponse response = await task.ConfigureAwait(false);
172172
foreach (var update in response.ToChatResponseUpdates())

test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatClientExtensionsTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void GetService_InvalidArgs_Throws()
1818
}
1919

2020
[Fact]
21-
public void CompleteAsync_InvalidArgs_Throws()
21+
public void GetResponseAsync_InvalidArgs_Throws()
2222
{
2323
Assert.Throws<ArgumentNullException>("client", () =>
2424
{
@@ -32,7 +32,7 @@ public void CompleteAsync_InvalidArgs_Throws()
3232
}
3333

3434
[Fact]
35-
public void CompleteStreamingAsync_InvalidArgs_Throws()
35+
public void GetStreamingResponseAsync_InvalidArgs_Throws()
3636
{
3737
Assert.Throws<ArgumentNullException>("client", () =>
3838
{
@@ -46,15 +46,15 @@ public void CompleteStreamingAsync_InvalidArgs_Throws()
4646
}
4747

4848
[Fact]
49-
public async Task CompleteAsync_CreatesTextMessageAsync()
49+
public async Task GetResponseAsync_CreatesTextMessageAsync()
5050
{
5151
var expectedResponse = new ChatResponse([new ChatMessage()]);
5252
var expectedOptions = new ChatOptions();
5353
using var cts = new CancellationTokenSource();
5454

5555
using TestChatClient client = new()
5656
{
57-
CompleteAsyncCallback = (chatMessages, options, cancellationToken) =>
57+
GetResponseAsyncCallback = (chatMessages, options, cancellationToken) =>
5858
{
5959
ChatMessage m = Assert.Single(chatMessages);
6060
Assert.Equal(ChatRole.User, m.Role);
@@ -74,14 +74,14 @@ public async Task CompleteAsync_CreatesTextMessageAsync()
7474
}
7575

7676
[Fact]
77-
public async Task CompleteStreamingAsync_CreatesTextMessageAsync()
77+
public async Task GetStreamingResponseAsync_CreatesTextMessageAsync()
7878
{
7979
var expectedOptions = new ChatOptions();
8080
using var cts = new CancellationTokenSource();
8181

8282
using TestChatClient client = new()
8383
{
84-
CompleteStreamingAsyncCallback = (chatMessages, options, cancellationToken) =>
84+
GetStreamingResponseAsyncCallback = (chatMessages, options, cancellationToken) =>
8585
{
8686
ChatMessage m = Assert.Single(chatMessages);
8787
Assert.Equal(ChatRole.User, m.Role);

test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/DelegatingChatClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task ChatAsyncDefaultsToInnerClientAsync()
2828
var expectedResponse = new ChatResponse([]);
2929
using var inner = new TestChatClient
3030
{
31-
CompleteAsyncCallback = (chatContents, options, cancellationToken) =>
31+
GetResponseAsyncCallback = (chatContents, options, cancellationToken) =>
3232
{
3333
Assert.Same(expectedChatContents, chatContents);
3434
Assert.Same(expectedChatOptions, options);
@@ -64,7 +64,7 @@ public async Task ChatStreamingAsyncDefaultsToInnerClientAsync()
6464

6565
using var inner = new TestChatClient
6666
{
67-
CompleteStreamingAsyncCallback = (chatContents, options, cancellationToken) =>
67+
GetStreamingResponseAsyncCallback = (chatContents, options, cancellationToken) =>
6868
{
6969
Assert.Same(expectedChatContents, chatContents);
7070
Assert.Same(expectedChatOptions, options);

test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/TestChatClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ public TestChatClient()
1717

1818
public IServiceProvider? Services { get; set; }
1919

20-
public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatResponse>>? CompleteAsyncCallback { get; set; }
20+
public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatResponse>>? GetResponseAsyncCallback { get; set; }
2121

22-
public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? CompleteStreamingAsyncCallback { get; set; }
22+
public Func<IList<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>>? GetStreamingResponseAsyncCallback { get; set; }
2323

2424
public Func<Type, object?, object?> GetServiceCallback { get; set; }
2525

2626
private object? DefaultGetServiceCallback(Type serviceType, object? serviceKey) =>
2727
serviceType is not null && serviceKey is null && serviceType.IsInstanceOfType(this) ? this : null;
2828

2929
public Task<ChatResponse> GetResponseAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
30-
=> CompleteAsyncCallback!.Invoke(chatMessages, options, cancellationToken);
30+
=> GetResponseAsyncCallback!.Invoke(chatMessages, options, cancellationToken);
3131

3232
public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IList<ChatMessage> chatMessages, ChatOptions? options = null, CancellationToken cancellationToken = default)
33-
=> CompleteStreamingAsyncCallback!.Invoke(chatMessages, options, cancellationToken);
33+
=> GetStreamingResponseAsyncCallback!.Invoke(chatMessages, options, cancellationToken);
3434

3535
public object? GetService(Type serviceType, object? serviceKey = null)
3636
=> GetServiceCallback(serviceType, serviceKey);

test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void Dispose()
4242
protected abstract IChatClient? CreateChatClient();
4343

4444
[ConditionalFact]
45-
public virtual async Task CompleteAsync_SingleRequestMessage()
45+
public virtual async Task GetResponseAsync_SingleRequestMessage()
4646
{
4747
SkipIfNotEnabled();
4848

@@ -52,7 +52,7 @@ public virtual async Task CompleteAsync_SingleRequestMessage()
5252
}
5353

5454
[ConditionalFact]
55-
public virtual async Task CompleteAsync_MultipleRequestMessages()
55+
public virtual async Task GetResponseAsync_MultipleRequestMessages()
5656
{
5757
SkipIfNotEnabled();
5858

@@ -71,7 +71,7 @@ public virtual async Task CompleteAsync_MultipleRequestMessages()
7171
}
7272

7373
[ConditionalFact]
74-
public virtual async Task CompleteStreamingAsync_SingleStreamingResponseChoice()
74+
public virtual async Task GetStreamingResponseAsync_SingleStreamingResponseChoice()
7575
{
7676
SkipIfNotEnabled();
7777

@@ -95,7 +95,7 @@ public virtual async Task CompleteStreamingAsync_SingleStreamingResponseChoice()
9595
}
9696

9797
[ConditionalFact]
98-
public virtual async Task CompleteAsync_UsageDataAvailable()
98+
public virtual async Task GetResponseAsync_UsageDataAvailable()
9999
{
100100
SkipIfNotEnabled();
101101

@@ -108,7 +108,7 @@ public virtual async Task CompleteAsync_UsageDataAvailable()
108108
}
109109

110110
[ConditionalFact]
111-
public virtual async Task CompleteStreamingAsync_UsageDataAvailable()
111+
public virtual async Task GetStreamingResponseAsync_UsageDataAvailable()
112112
{
113113
SkipIfNotEnabled();
114114

@@ -631,7 +631,7 @@ public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics()
631631
}
632632

633633
[ConditionalFact]
634-
public virtual async Task CompleteAsync_StructuredOutput()
634+
public virtual async Task GetResponseAsync_StructuredOutput()
635635
{
636636
SkipIfNotEnabled();
637637

@@ -647,7 +647,7 @@ Who is described in the following sentence?
647647
}
648648

649649
[ConditionalFact]
650-
public virtual async Task CompleteAsync_StructuredOutputArray()
650+
public virtual async Task GetResponseAsync_StructuredOutputArray()
651651
{
652652
SkipIfNotEnabled();
653653

@@ -663,7 +663,7 @@ Who are described in the following sentence?
663663
}
664664

665665
[ConditionalFact]
666-
public virtual async Task CompleteAsync_StructuredOutputInteger()
666+
public virtual async Task GetResponseAsync_StructuredOutputInteger()
667667
{
668668
SkipIfNotEnabled();
669669

@@ -676,7 +676,7 @@ To fix this we added another one. How many are there now?
676676
}
677677

678678
[ConditionalFact]
679-
public virtual async Task CompleteAsync_StructuredOutputString()
679+
public virtual async Task GetResponseAsync_StructuredOutputString()
680680
{
681681
SkipIfNotEnabled();
682682

@@ -689,7 +689,7 @@ public virtual async Task CompleteAsync_StructuredOutputString()
689689
}
690690

691691
[ConditionalFact]
692-
public virtual async Task CompleteAsync_StructuredOutputBool_True()
692+
public virtual async Task GetResponseAsync_StructuredOutputBool_True()
693693
{
694694
SkipIfNotEnabled();
695695

@@ -702,7 +702,7 @@ Is there at least one software developer from Cardiff?
702702
}
703703

704704
[ConditionalFact]
705-
public virtual async Task CompleteAsync_StructuredOutputBool_False()
705+
public virtual async Task GetResponseAsync_StructuredOutputBool_False()
706706
{
707707
SkipIfNotEnabled();
708708

@@ -715,7 +715,7 @@ Can we be sure that he is a medical doctor?
715715
}
716716

717717
[ConditionalFact]
718-
public virtual async Task CompleteAsync_StructuredOutputEnum()
718+
public virtual async Task GetResponseAsync_StructuredOutputEnum()
719719
{
720720
SkipIfNotEnabled();
721721

@@ -727,7 +727,7 @@ Taylor Swift is a famous singer and songwriter. What is her job?
727727
}
728728

729729
[ConditionalFact]
730-
public virtual async Task CompleteAsync_StructuredOutput_WithFunctions()
730+
public virtual async Task GetResponseAsync_StructuredOutput_WithFunctions()
731731
{
732732
SkipIfNotEnabled();
733733

@@ -758,7 +758,7 @@ public virtual async Task CompleteAsync_StructuredOutput_WithFunctions()
758758
}
759759

760760
[ConditionalFact]
761-
public virtual async Task CompleteAsync_StructuredOutput_Native()
761+
public virtual async Task GetResponseAsync_StructuredOutput_Native()
762762
{
763763
SkipIfNotEnabled();
764764

test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ReducingChatClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public async Task Reduction_LimitsMessagesBasedOnTokenLimit()
2727
{
2828
using var innerClient = new TestChatClient
2929
{
30-
CompleteAsyncCallback = (messages, options, cancellationToken) =>
30+
GetResponseAsyncCallback = (messages, options, cancellationToken) =>
3131
{
3232
Assert.Equal(2, messages.Count);
3333
Assert.Collection(messages,

test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ChatClientStructuredOutputExtensionsTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task SuccessUsage()
2828

2929
using var client = new TestChatClient
3030
{
31-
CompleteAsyncCallback = (messages, options, cancellationToken) =>
31+
GetResponseAsyncCallback = (messages, options, cancellationToken) =>
3232
{
3333
var responseFormat = Assert.IsType<ChatResponseFormatJson>(options!.ResponseFormat);
3434
Assert.Null(responseFormat.Schema);
@@ -82,7 +82,7 @@ public async Task WrapsNonObjectValuesInDataProperty()
8282

8383
using var client = new TestChatClient
8484
{
85-
CompleteAsyncCallback = (messages, options, cancellationToken) =>
85+
GetResponseAsyncCallback = (messages, options, cancellationToken) =>
8686
{
8787
var suppliedSchemaMatch = Regex.Match(messages[1].Text!, "```(.*?)```", RegexOptions.Singleline);
8888
Assert.True(suppliedSchemaMatch.Success);
@@ -113,7 +113,7 @@ public async Task FailureUsage_InvalidJson()
113113
var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "This is not valid JSON"));
114114
using var client = new TestChatClient
115115
{
116-
CompleteAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse),
116+
GetResponseAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse),
117117
};
118118

119119
var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
@@ -132,7 +132,7 @@ public async Task FailureUsage_NullJson()
132132
var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, "null"));
133133
using var client = new TestChatClient
134134
{
135-
CompleteAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse),
135+
GetResponseAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse),
136136
};
137137

138138
var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
@@ -151,7 +151,7 @@ public async Task FailureUsage_NoJsonInResponse()
151151
var expectedResponse = new ChatResponse(new ChatMessage(ChatRole.Assistant, [new DataContent("https://example.com")]));
152152
using var client = new TestChatClient
153153
{
154-
CompleteAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse),
154+
GetResponseAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse),
155155
};
156156

157157
var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
@@ -172,7 +172,7 @@ public async Task CanUseNativeStructuredOutput()
172172

173173
using var client = new TestChatClient
174174
{
175-
CompleteAsyncCallback = (messages, options, cancellationToken) =>
175+
GetResponseAsyncCallback = (messages, options, cancellationToken) =>
176176
{
177177
var responseFormat = Assert.IsType<ChatResponseFormatJson>(options!.ResponseFormat);
178178
Assert.Equal(nameof(Animal), responseFormat.SchemaName);
@@ -216,7 +216,7 @@ public async Task CanUseNativeStructuredOutputWithSanitizedTypeName()
216216

217217
using var client = new TestChatClient
218218
{
219-
CompleteAsyncCallback = (messages, options, cancellationToken) =>
219+
GetResponseAsyncCallback = (messages, options, cancellationToken) =>
220220
{
221221
var responseFormat = Assert.IsType<ChatResponseFormatJson>(options!.ResponseFormat);
222222

@@ -251,7 +251,7 @@ public async Task CanUseNativeStructuredOutputWithArray()
251251

252252
using var client = new TestChatClient
253253
{
254-
CompleteAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse)
254+
GetResponseAsyncCallback = (messages, options, cancellationToken) => Task.FromResult(expectedResponse)
255255
};
256256

257257
var chatHistory = new List<ChatMessage> { new(ChatRole.User, "Hello") };
@@ -282,7 +282,7 @@ public async Task CanSpecifyCustomJsonSerializationOptions()
282282

283283
using var client = new TestChatClient
284284
{
285-
CompleteAsyncCallback = (messages, options, cancellationToken) =>
285+
GetResponseAsyncCallback = (messages, options, cancellationToken) =>
286286
{
287287
Assert.Collection(messages,
288288
message => Assert.Equal("Hello", message.Text),
@@ -322,7 +322,7 @@ public async Task HandlesBackendReturningMultipleObjects()
322322

323323
using var client = new TestChatClient
324324
{
325-
CompleteAsyncCallback = (messages, options, cancellationToken) =>
325+
GetResponseAsyncCallback = (messages, options, cancellationToken) =>
326326
{
327327
return Task.FromResult(new ChatResponse(new ChatMessage(ChatRole.Assistant, resultDuplicatedJson)));
328328
},

test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ConfigureOptionsChatClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ public async Task ConfigureOptions_ReturnedInstancePassedToNextClient(bool nullP
4040

4141
using IChatClient innerClient = new TestChatClient
4242
{
43-
CompleteAsyncCallback = (messages, options, cancellationToken) =>
43+
GetResponseAsyncCallback = (messages, options, cancellationToken) =>
4444
{
4545
Assert.Same(returnedOptions, options);
4646
Assert.Equal(cts.Token, cancellationToken);
4747
return Task.FromResult(expectedResponse);
4848
},
4949

50-
CompleteStreamingAsyncCallback = (messages, options, cancellationToken) =>
50+
GetStreamingResponseAsyncCallback = (messages, options, cancellationToken) =>
5151
{
5252
Assert.Same(returnedOptions, options);
5353
Assert.Equal(cts.Token, cancellationToken);

0 commit comments

Comments
 (0)