Skip to content

Commit da2e0b4

Browse files
committed
Rename IChatClient members and corresponding types
After great feedback on usage of the APIs, re-reviewing the state of the ecosystem, and length discussions, we're renaming the members of IChatClient to destress the notion of "completions" and instead focus just on getting back a {streaming} response.
1 parent 766d03f commit da2e0b4

File tree

63 files changed

+1049
-1049
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1049
-1049
lines changed

src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatClientExtensions.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public static class ChatClientExtensions
2727
return (TService?)client.GetService(typeof(TService), serviceKey);
2828
}
2929

30-
/// <summary>Sends a user chat text message to the model and returns the response messages.</summary>
30+
/// <summary>Sends a user chat text message and returns the response messages.</summary>
3131
/// <param name="client">The chat client.</param>
3232
/// <param name="chatMessage">The text content for the chat message to send.</param>
3333
/// <param name="options">The chat options to configure the request.</param>
3434
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
3535
/// <returns>The response messages generated by the client.</returns>
36-
public static Task<ChatCompletion> CompleteAsync(
36+
public static Task<ChatResponse> GetResponseAsync(
3737
this IChatClient client,
3838
string chatMessage,
3939
ChatOptions? options = null,
@@ -42,16 +42,16 @@ public static Task<ChatCompletion> CompleteAsync(
4242
_ = Throw.IfNull(client);
4343
_ = Throw.IfNull(chatMessage);
4444

45-
return client.CompleteAsync(new ChatMessage(ChatRole.User, chatMessage), options, cancellationToken);
45+
return client.GetResponseAsync(new ChatMessage(ChatRole.User, chatMessage), options, cancellationToken);
4646
}
4747

48-
/// <summary>Sends a chat message to the model and returns the response messages.</summary>
48+
/// <summary>Sends a chat message and returns the response messages.</summary>
4949
/// <param name="client">The chat client.</param>
5050
/// <param name="chatMessage">The chat message to send.</param>
5151
/// <param name="options">The chat options to configure the request.</param>
5252
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
5353
/// <returns>The response messages generated by the client.</returns>
54-
public static Task<ChatCompletion> CompleteAsync(
54+
public static Task<ChatResponse> GetResponseAsync(
5555
this IChatClient client,
5656
ChatMessage chatMessage,
5757
ChatOptions? options = null,
@@ -60,16 +60,16 @@ public static Task<ChatCompletion> CompleteAsync(
6060
_ = Throw.IfNull(client);
6161
_ = Throw.IfNull(chatMessage);
6262

63-
return client.CompleteAsync([chatMessage], options, cancellationToken);
63+
return client.GetResponseAsync([chatMessage], options, cancellationToken);
6464
}
6565

66-
/// <summary>Sends a user chat text message to the model and streams the response messages.</summary>
66+
/// <summary>Sends a user chat text message and streams the response messages.</summary>
6767
/// <param name="client">The chat client.</param>
6868
/// <param name="chatMessage">The text content for the chat message to send.</param>
6969
/// <param name="options">The chat options to configure the request.</param>
7070
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
7171
/// <returns>The response messages generated by the client.</returns>
72-
public static IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(
72+
public static IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
7373
this IChatClient client,
7474
string chatMessage,
7575
ChatOptions? options = null,
@@ -78,16 +78,16 @@ public static IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingA
7878
_ = Throw.IfNull(client);
7979
_ = Throw.IfNull(chatMessage);
8080

81-
return client.CompleteStreamingAsync(new ChatMessage(ChatRole.User, chatMessage), options, cancellationToken);
81+
return client.GetStreamingResponseAsync(new ChatMessage(ChatRole.User, chatMessage), options, cancellationToken);
8282
}
8383

84-
/// <summary>Sends a chat message to the model and streams the response messages.</summary>
84+
/// <summary>Sends a chat message and streams the response messages.</summary>
8585
/// <param name="client">The chat client.</param>
8686
/// <param name="chatMessage">The chat message to send.</param>
8787
/// <param name="options">The chat options to configure the request.</param>
8888
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
8989
/// <returns>The response messages generated by the client.</returns>
90-
public static IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(
90+
public static IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
9191
this IChatClient client,
9292
ChatMessage chatMessage,
9393
ChatOptions? options = null,
@@ -96,6 +96,6 @@ public static IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingA
9696
_ = Throw.IfNull(client);
9797
_ = Throw.IfNull(chatMessage);
9898

99-
return client.CompleteStreamingAsync([chatMessage], options, cancellationToken);
99+
return client.GetStreamingResponseAsync([chatMessage], options, cancellationToken);
100100
}
101101
}

src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatClientMetadata.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ public class ChatClientMetadata
1010
{
1111
/// <summary>Initializes a new instance of the <see cref="ChatClientMetadata"/> class.</summary>
1212
/// <param name="providerName">
13-
/// The name of the chat completion provider, if applicable. Where possible, this should map to the
13+
/// The name of the chat provider, if applicable. Where possible, this should map to the
1414
/// appropriate name defined in the OpenTelemetry Semantic Conventions for Generative AI systems.
1515
/// </param>
16-
/// <param name="providerUri">The URL for accessing the chat completion provider, if applicable.</param>
17-
/// <param name="modelId">The ID of the chat completion model used, if applicable.</param>
16+
/// <param name="providerUri">The URL for accessing the chat provider, if applicable.</param>
17+
/// <param name="modelId">The ID of the chat model used, if applicable.</param>
1818
public ChatClientMetadata(string? providerName = null, Uri? providerUri = null, string? modelId = null)
1919
{
2020
ModelId = modelId;
2121
ProviderName = providerName;
2222
ProviderUri = providerUri;
2323
}
2424

25-
/// <summary>Gets the name of the chat completion provider.</summary>
25+
/// <summary>Gets the name of the chat provider.</summary>
2626
/// <remarks>
2727
/// Where possible, this maps to the appropriate name defined in the
2828
/// OpenTelemetry Semantic Conventions for Generative AI systems.
2929
/// </remarks>
3030
public string? ProviderName { get; }
3131

32-
/// <summary>Gets the URL for accessing the chat completion provider.</summary>
32+
/// <summary>Gets the URL for accessing the chat provider.</summary>
3333
public Uri? ProviderUri { get; }
3434

35-
/// <summary>Gets the ID of the model used by this chat completion provider.</summary>
35+
/// <summary>Gets the ID of the model used by this chat provider.</summary>
3636
/// <remarks>
3737
/// This value can be null if either the name is unknown or there are multiple possible models associated with this instance.
3838
/// An individual request may override this value via <see cref="ChatOptions.ModelId"/>.

src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatCompletion.cs renamed to src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponse.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,36 @@
99

1010
namespace Microsoft.Extensions.AI;
1111

12-
/// <summary>Represents the result of a chat completion request.</summary>
13-
public class ChatCompletion
12+
/// <summary>Represents the response to a chat request.</summary>
13+
public class ChatResponse
1414
{
15-
/// <summary>The list of choices in the completion.</summary>
15+
/// <summary>The list of choices in the response.</summary>
1616
private IList<ChatMessage> _choices;
1717

18-
/// <summary>Initializes a new instance of the <see cref="ChatCompletion"/> class.</summary>
19-
/// <param name="choices">The list of choices in the completion, one message per choice.</param>
18+
/// <summary>Initializes a new instance of the <see cref="ChatResponse"/> class.</summary>
19+
/// <param name="choices">The list of choices in the response, one message per choice.</param>
2020
[JsonConstructor]
21-
public ChatCompletion(IList<ChatMessage> choices)
21+
public ChatResponse(IList<ChatMessage> choices)
2222
{
2323
_choices = Throw.IfNull(choices);
2424
}
2525

26-
/// <summary>Initializes a new instance of the <see cref="ChatCompletion"/> class.</summary>
27-
/// <param name="message">The chat message representing the singular choice in the completion.</param>
28-
public ChatCompletion(ChatMessage message)
26+
/// <summary>Initializes a new instance of the <see cref="ChatResponse"/> class.</summary>
27+
/// <param name="message">The chat message representing the singular choice in the response.</param>
28+
public ChatResponse(ChatMessage message)
2929
{
3030
_ = Throw.IfNull(message);
3131
_choices = [message];
3232
}
3333

34-
/// <summary>Gets or sets the list of chat completion choices.</summary>
34+
/// <summary>Gets or sets the list of chat response choices.</summary>
3535
public IList<ChatMessage> Choices
3636
{
3737
get => _choices;
3838
set => _choices = Throw.IfNull(value);
3939
}
4040

41-
/// <summary>Gets the chat completion message.</summary>
41+
/// <summary>Gets the chat response message.</summary>
4242
/// <remarks>
4343
/// If there are multiple choices, this property returns the first choice.
4444
/// If <see cref="Choices"/> is empty, this property will throw. Use <see cref="Choices"/> to access all choices directly.
@@ -51,48 +51,48 @@ public ChatMessage Message
5151
var choices = Choices;
5252
if (choices.Count == 0)
5353
{
54-
throw new InvalidOperationException($"The {nameof(ChatCompletion)} instance does not contain any {nameof(ChatMessage)} choices.");
54+
throw new InvalidOperationException($"The {nameof(ChatResponse)} instance does not contain any {nameof(ChatMessage)} choices.");
5555
}
5656

5757
return choices[0];
5858
}
5959
}
6060

61-
/// <summary>Gets or sets the ID of the chat completion.</summary>
62-
public string? CompletionId { get; set; }
61+
/// <summary>Gets or sets the ID of the chat response.</summary>
62+
public string? ResponseId { get; set; }
6363

64-
/// <summary>Gets or sets the chat thread ID associated with this chat completion.</summary>
64+
/// <summary>Gets or sets the chat thread ID associated with this chat response.</summary>
6565
/// <remarks>
6666
/// Some <see cref="IChatClient"/> implementations are capable of storing the state for a chat thread, such that
67-
/// the input messages supplied to <see cref="IChatClient.CompleteAsync"/> need only be the additional messages beyond
67+
/// the input messages supplied to <see cref="IChatClient.GetResponseAsync"/> need only be the additional messages beyond
6868
/// what's already stored. If this property is non-<see langword="null"/>, it represents an identifier for that state,
6969
/// and it should be used in a subsequent <see cref="ChatOptions.ChatThreadId"/> instead of supplying the same messages
70-
/// (and this <see cref="ChatCompletion"/>'s message) as part of the <c>chatMessages</c> parameter.
70+
/// (and this <see cref="ChatResponse"/>'s message) as part of the <c>chatMessages</c> parameter.
7171
/// </remarks>
7272
public string? ChatThreadId { get; set; }
7373

74-
/// <summary>Gets or sets the model ID used in the creation of the chat completion.</summary>
74+
/// <summary>Gets or sets the model ID used in the creation of the chat response.</summary>
7575
public string? ModelId { get; set; }
7676

77-
/// <summary>Gets or sets a timestamp for the chat completion.</summary>
77+
/// <summary>Gets or sets a timestamp for the chat response.</summary>
7878
public DateTimeOffset? CreatedAt { get; set; }
7979

80-
/// <summary>Gets or sets the reason for the chat completion.</summary>
80+
/// <summary>Gets or sets the reason for the chat response.</summary>
8181
public ChatFinishReason? FinishReason { get; set; }
8282

83-
/// <summary>Gets or sets usage details for the chat completion.</summary>
83+
/// <summary>Gets or sets usage details for the chat response.</summary>
8484
public UsageDetails? Usage { get; set; }
8585

86-
/// <summary>Gets or sets the raw representation of the chat completion from an underlying implementation.</summary>
86+
/// <summary>Gets or sets the raw representation of the chat response from an underlying implementation.</summary>
8787
/// <remarks>
88-
/// If a <see cref="ChatCompletion"/> is created to represent some underlying object from another object
88+
/// If a <see cref="ChatResponse"/> is created to represent some underlying object from another object
8989
/// model, this property can be used to store that original object. This can be useful for debugging or
9090
/// for enabling a consumer to access the underlying object model if needed.
9191
/// </remarks>
9292
[JsonIgnore]
9393
public object? RawRepresentation { get; set; }
9494

95-
/// <summary>Gets or sets any additional properties associated with the chat completion.</summary>
95+
/// <summary>Gets or sets any additional properties associated with the chat response.</summary>
9696
public AdditionalPropertiesDictionary? AdditionalProperties { get; set; }
9797

9898
/// <inheritdoc />
@@ -117,14 +117,14 @@ public override string ToString()
117117
return sb.ToString();
118118
}
119119

120-
/// <summary>Creates an array of <see cref="StreamingChatCompletionUpdate" /> instances that represent this <see cref="ChatCompletion" />.</summary>
121-
/// <returns>An array of <see cref="StreamingChatCompletionUpdate" /> instances that may be used to represent this <see cref="ChatCompletion" />.</returns>
122-
public StreamingChatCompletionUpdate[] ToStreamingChatCompletionUpdates()
120+
/// <summary>Creates an array of <see cref="ChatResponseUpdate" /> instances that represent this <see cref="ChatResponse" />.</summary>
121+
/// <returns>An array of <see cref="ChatResponseUpdate" /> instances that may be used to represent this <see cref="ChatResponse" />.</returns>
122+
public ChatResponseUpdate[] ToChatResponseUpdates()
123123
{
124-
StreamingChatCompletionUpdate? extra = null;
124+
ChatResponseUpdate? extra = null;
125125
if (AdditionalProperties is not null || Usage is not null)
126126
{
127-
extra = new StreamingChatCompletionUpdate
127+
extra = new ChatResponseUpdate
128128
{
129129
AdditionalProperties = AdditionalProperties
130130
};
@@ -136,12 +136,12 @@ public StreamingChatCompletionUpdate[] ToStreamingChatCompletionUpdates()
136136
}
137137

138138
int choicesCount = Choices.Count;
139-
var updates = new StreamingChatCompletionUpdate[choicesCount + (extra is null ? 0 : 1)];
139+
var updates = new ChatResponseUpdate[choicesCount + (extra is null ? 0 : 1)];
140140

141141
for (int choiceIndex = 0; choiceIndex < choicesCount; choiceIndex++)
142142
{
143143
ChatMessage choice = Choices[choiceIndex];
144-
updates[choiceIndex] = new StreamingChatCompletionUpdate
144+
updates[choiceIndex] = new ChatResponseUpdate
145145
{
146146
ChatThreadId = ChatThreadId,
147147
ChoiceIndex = choiceIndex,
@@ -152,7 +152,7 @@ public StreamingChatCompletionUpdate[] ToStreamingChatCompletionUpdates()
152152
RawRepresentation = choice.RawRepresentation,
153153
Role = choice.Role,
154154

155-
CompletionId = CompletionId,
155+
ResponseId = ResponseId,
156156
CreatedAt = CreatedAt,
157157
FinishReason = FinishReason,
158158
ModelId = ModelId

0 commit comments

Comments
 (0)