Skip to content

Fix up a few more stale references to Complete{Streaming}Async (mainly tests) #5876

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

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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<ChatResponseUpdate> CompleteStreamingAsyncViaCompleteAsync(Task<ChatResponse> task)
static async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsyncViaGetResponseAsync(Task<ChatResponse> task)
{
ChatResponse response = await task.ConfigureAwait(false);
foreach (var update in response.ToChatResponseUpdates())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void GetService_InvalidArgs_Throws()
}

[Fact]
public void CompleteAsync_InvalidArgs_Throws()
public void GetResponseAsync_InvalidArgs_Throws()
{
Assert.Throws<ArgumentNullException>("client", () =>
{
Expand All @@ -32,7 +32,7 @@ public void CompleteAsync_InvalidArgs_Throws()
}

[Fact]
public void CompleteStreamingAsync_InvalidArgs_Throws()
public void GetStreamingResponseAsync_InvalidArgs_Throws()
{
Assert.Throws<ArgumentNullException>("client", () =>
{
Expand All @@ -46,15 +46,15 @@ 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();
using var cts = new CancellationTokenSource();

using TestChatClient client = new()
{
CompleteAsyncCallback = (chatMessages, options, cancellationToken) =>
GetResponseAsyncCallback = (chatMessages, options, cancellationToken) =>
{
ChatMessage m = Assert.Single(chatMessages);
Assert.Equal(ChatRole.User, m.Role);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public TestChatClient()

public IServiceProvider? Services { get; set; }

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

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

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

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

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

public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IList<ChatMessage> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -52,7 +52,7 @@ public virtual async Task CompleteAsync_SingleRequestMessage()
}

[ConditionalFact]
public virtual async Task CompleteAsync_MultipleRequestMessages()
public virtual async Task GetResponseAsync_MultipleRequestMessages()
{
SkipIfNotEnabled();

Expand All @@ -71,7 +71,7 @@ public virtual async Task CompleteAsync_MultipleRequestMessages()
}

[ConditionalFact]
public virtual async Task CompleteStreamingAsync_SingleStreamingResponseChoice()
public virtual async Task GetStreamingResponseAsync_SingleStreamingResponseChoice()
{
SkipIfNotEnabled();

Expand All @@ -95,7 +95,7 @@ public virtual async Task CompleteStreamingAsync_SingleStreamingResponseChoice()
}

[ConditionalFact]
public virtual async Task CompleteAsync_UsageDataAvailable()
public virtual async Task GetResponseAsync_UsageDataAvailable()
{
SkipIfNotEnabled();

Expand All @@ -108,7 +108,7 @@ public virtual async Task CompleteAsync_UsageDataAvailable()
}

[ConditionalFact]
public virtual async Task CompleteStreamingAsync_UsageDataAvailable()
public virtual async Task GetStreamingResponseAsync_UsageDataAvailable()
{
SkipIfNotEnabled();

Expand Down Expand Up @@ -631,7 +631,7 @@ public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics()
}

[ConditionalFact]
public virtual async Task CompleteAsync_StructuredOutput()
public virtual async Task GetResponseAsync_StructuredOutput()
{
SkipIfNotEnabled();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatResponseFormatJson>(options!.ResponseFormat);
Assert.Null(responseFormat.Schema);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<ChatMessage> { new(ChatRole.User, "Hello") };
Expand All @@ -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<ChatMessage> { new(ChatRole.User, "Hello") };
Expand All @@ -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<ChatMessage> { new(ChatRole.User, "Hello") };
Expand All @@ -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<ChatResponseFormatJson>(options!.ResponseFormat);
Assert.Equal(nameof(Animal), responseFormat.SchemaName);
Expand Down Expand Up @@ -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<ChatResponseFormatJson>(options!.ResponseFormat);

Expand Down Expand Up @@ -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<ChatMessage> { new(ChatRole.User, "Hello") };
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading