Skip to content

Commit 3d8f0c1

Browse files
committed
Restore deleted members as obsolete (#6304)
* Restore EmbeddingGeneratorExtensions members as obsolete * Restore ChatThreadId as obsolete * Restore ChatResponse.ChatThreadId and ChatResponseUpdate.ChatThreadId as obsolete. * Remove the tests for obsolete members * Remove the Embeddings tests for obsolete members
1 parent a9ff0cc commit 3d8f0c1

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ namespace Microsoft.Extensions.AI;
99
/// <summary>Represents the options for a chat request.</summary>
1010
public class ChatOptions
1111
{
12+
/// <summary>Gets or sets an optional identifier used to associate a request with an existing conversation.</summary>
13+
/// <remarks>This property is obsolete. Use <see cref="ConversationId"/> instead.</remarks>
14+
[System.Obsolete("Use ConversationId instead.")]
15+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
16+
public string? ChatThreadId
17+
{
18+
get => ConversationId;
19+
set => ConversationId = value;
20+
}
21+
1222
/// <summary>Gets or sets an optional identifier used to associate a request with an existing conversation.</summary>
1323
public string? ConversationId { get; set; }
1424

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,25 @@ public IList<ChatMessage> Messages
6363
/// <summary>Gets or sets the ID of the chat response.</summary>
6464
public string? ResponseId { get; set; }
6565

66+
/// <summary>Gets or sets an identifier for the state of the conversation.</summary>
67+
/// <remarks>
68+
/// Some <see cref="IChatClient"/> implementations are capable of storing the state for a conversation, such that
69+
/// the input messages supplied to <see cref="IChatClient.GetResponseAsync"/> need only be the additional messages beyond
70+
/// what's already stored. If this property is non-<see langword="null"/>, it represents an identifier for that state,
71+
/// and it should be used in a subsequent <see cref="ChatOptions.ConversationId"/> instead of supplying the same messages
72+
/// (and this <see cref="ChatResponse"/>'s message) as part of the <c>messages</c> parameter. Note that the value may
73+
/// or may not differ on every response, depending on whether the underlying provider uses a fixed ID for each conversation
74+
/// or updates it for each message.
75+
/// </remarks>
76+
/// <remarks>This method is obsolete. Use <see cref="ConversationId"/> instead.</remarks>
77+
[Obsolete("Use ConversationId instead.")]
78+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
79+
public string? ChatThreadId
80+
{
81+
get => ConversationId;
82+
set => ConversationId = value;
83+
}
84+
6685
/// <summary>Gets or sets an identifier for the state of the conversation.</summary>
6786
/// <remarks>
6887
/// Some <see cref="IChatClient"/> implementations are capable of storing the state for a conversation, such that

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ public IList<AIContent> Contents
116116
/// </remarks>
117117
public string? MessageId { get; set; }
118118

119+
/// <summary>Gets or sets an identifier for the state of the conversation of which this update is a part.</summary>
120+
/// <remarks>
121+
/// Some <see cref="IChatClient"/> implementations are capable of storing the state for a conversation, such that
122+
/// the input messages supplied to <see cref="IChatClient.GetStreamingResponseAsync"/> need only be the additional messages beyond
123+
/// what's already stored. If this property is non-<see langword="null"/>, it represents an identifier for that state,
124+
/// and it should be used in a subsequent <see cref="ChatOptions.ConversationId"/> instead of supplying the same messages
125+
/// (and this streaming message) as part of the <c>messages</c> parameter. Note that the value may or may not differ on every
126+
/// response, depending on whether the underlying provider uses a fixed ID for each conversation or updates it for each message.
127+
/// </remarks>
128+
/// <remarks>This method is obsolete. Use <see cref="ConversationId"/> instead.</remarks>
129+
[Obsolete("Use ConversationId instead.")]
130+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
131+
public string? ChatThreadId
132+
{
133+
get => ConversationId;
134+
set => ConversationId = value;
135+
}
136+
119137
/// <summary>Gets or sets an identifier for the state of the conversation of which this update is a part.</summary>
120138
/// <remarks>
121139
/// Some <see cref="IChatClient"/> implementations are capable of storing the state for a conversation, such that

src/Libraries/Microsoft.Extensions.AI.Abstractions/Embeddings/EmbeddingGeneratorExtensions.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,35 @@ public static TService GetRequiredService<TService>(
8787
return service;
8888
}
8989

90+
/// <summary>Generates an embedding vector from the specified <paramref name="value"/>.</summary>
91+
/// <typeparam name="TInput">The type from which embeddings will be generated.</typeparam>
92+
/// <typeparam name="TEmbeddingElement">The numeric type of the embedding data.</typeparam>
93+
/// <param name="generator">The embedding generator.</param>
94+
/// <param name="value">A value from which an embedding will be generated.</param>
95+
/// <param name="options">The embedding generation options to configure the request.</param>
96+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
97+
/// <returns>The generated embedding for the specified <paramref name="value"/>.</returns>
98+
/// <exception cref="ArgumentNullException"><paramref name="generator"/> is <see langword="null"/>.</exception>
99+
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
100+
/// <exception cref="InvalidOperationException">The generator did not produce exactly one embedding.</exception>
101+
/// <remarks>
102+
/// This operation is equivalent to using <see cref="GenerateAsync"/> and returning the
103+
/// resulting <see cref="Embedding{T}"/>'s <see cref="Embedding{T}.Vector"/> property.
104+
/// </remarks>
105+
/// <remarks>
106+
/// This method is obsolete. Use <see cref="GenerateVectorAsync{TInput, TEmbeddingElement}"/> instead.
107+
/// </remarks>
108+
[Obsolete("Use GenerateVectorAsync<TInput, TEmbeddingElement> instead.")]
109+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
110+
public static async Task<ReadOnlyMemory<TEmbeddingElement>> GenerateEmbeddingVectorAsync<TInput, TEmbeddingElement>(
111+
this IEmbeddingGenerator<TInput, Embedding<TEmbeddingElement>> generator,
112+
TInput value,
113+
EmbeddingGenerationOptions? options = null,
114+
CancellationToken cancellationToken = default)
115+
{
116+
return await GenerateVectorAsync(generator, value, options, cancellationToken).ConfigureAwait(false);
117+
}
118+
90119
/// <summary>Generates an embedding vector from the specified <paramref name="value"/>.</summary>
91120
/// <typeparam name="TInput">The type from which embeddings will be generated.</typeparam>
92121
/// <typeparam name="TEmbeddingElement">The numeric type of the embedding data.</typeparam>
@@ -112,6 +141,39 @@ public static async Task<ReadOnlyMemory<TEmbeddingElement>> GenerateVectorAsync<
112141
return embedding.Vector;
113142
}
114143

144+
/// <summary>Generates an embedding from the specified <paramref name="value"/>.</summary>
145+
/// <typeparam name="TInput">The type from which embeddings will be generated.</typeparam>
146+
/// <typeparam name="TEmbedding">The type of embedding to generate.</typeparam>
147+
/// <param name="generator">The embedding generator.</param>
148+
/// <param name="value">A value from which an embedding will be generated.</param>
149+
/// <param name="options">The embedding generation options to configure the request.</param>
150+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
151+
/// <returns>
152+
/// The generated embedding for the specified <paramref name="value"/>.
153+
/// </returns>
154+
/// <exception cref="ArgumentNullException"><paramref name="generator"/> is <see langword="null"/>.</exception>
155+
/// <exception cref="ArgumentNullException"><paramref name="value"/> is <see langword="null"/>.</exception>
156+
/// <exception cref="InvalidOperationException">The generator did not produce exactly one embedding.</exception>
157+
/// <remarks>
158+
/// This operations is equivalent to using <see cref="IEmbeddingGenerator{TInput, TEmbedding}.GenerateAsync"/> with a
159+
/// collection composed of the single <paramref name="value"/> and then returning the first embedding element from the
160+
/// resulting <see cref="GeneratedEmbeddings{TEmbedding}"/> collection.
161+
/// </remarks>
162+
/// <remarks>
163+
/// This method is obsolete. Use <see cref="GenerateAsync{TInput, TEmbedding}"/> instead.
164+
/// </remarks>
165+
[Obsolete("Use GenerateAsync<TInput, TEmbedding> instead.")]
166+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
167+
public static async Task<TEmbedding> GenerateEmbeddingAsync<TInput, TEmbedding>(
168+
this IEmbeddingGenerator<TInput, TEmbedding> generator,
169+
TInput value,
170+
EmbeddingGenerationOptions? options = null,
171+
CancellationToken cancellationToken = default)
172+
where TEmbedding : Embedding
173+
{
174+
return await GenerateAsync(generator, value, options, cancellationToken).ConfigureAwait(false);
175+
}
176+
115177
/// <summary>Generates an embedding from the specified <paramref name="value"/>.</summary>
116178
/// <typeparam name="TInput">The type from which embeddings will be generated.</typeparam>
117179
/// <typeparam name="TEmbedding">The type of embedding to generate.</typeparam>

0 commit comments

Comments
 (0)