Skip to content

Commit c65858f

Browse files
committed
Remove non-AsXx surface area from M.E.AI.OpenAI/AzureAIInference
We expect the AsChatClient/AsEmbeddingGenerator extension methods from M.E.AI.OpenAI and M.E.AI.AzureAIInference to move into the OpenAI / Azure.AI.Inference libraries, respectively. To prepare for that, and the temporary M.E.AI.OpenAI/AzureAIInference libs then being deprecated, this PR removes the other surface area from these assemblies. For anything folks found useful, we should find another way to ship it, likely just as sample source somewhere.
1 parent 824ff6e commit c65858f

21 files changed

+10
-2115
lines changed

src/Libraries/Microsoft.Extensions.AI.AzureAIInference/AzureAIInferenceChatClient.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@
2222
namespace Microsoft.Extensions.AI;
2323

2424
/// <summary>Represents an <see cref="IChatClient"/> for an Azure AI Inference <see cref="ChatCompletionsClient"/>.</summary>
25-
public sealed class AzureAIInferenceChatClient : IChatClient
25+
internal sealed class AzureAIInferenceChatClient : IChatClient
2626
{
2727
/// <summary>Metadata about the client.</summary>
2828
private readonly ChatClientMetadata _metadata;
2929

3030
/// <summary>The underlying <see cref="ChatCompletionsClient" />.</summary>
3131
private readonly ChatCompletionsClient _chatCompletionsClient;
3232

33-
/// <summary>The <see cref="JsonSerializerOptions"/> use for any serialization activities related to tool call arguments and results.</summary>
34-
private JsonSerializerOptions _toolCallJsonSerializerOptions = AIJsonUtilities.DefaultOptions;
35-
3633
/// <summary>Gets a ChatRole.Developer value.</summary>
3734
private static ChatRole ChatRoleDeveloper { get; } = new("developer");
3835

@@ -62,13 +59,6 @@ public AzureAIInferenceChatClient(ChatCompletionsClient chatCompletionsClient, s
6259
_metadata = new("az.ai.inference", providerUrl, modelId);
6360
}
6461

65-
/// <summary>Gets or sets <see cref="JsonSerializerOptions"/> to use for any serialization activities related to tool call arguments and results.</summary>
66-
public JsonSerializerOptions ToolCallJsonSerializerOptions
67-
{
68-
get => _toolCallJsonSerializerOptions;
69-
set => _toolCallJsonSerializerOptions = Throw.IfNull(value);
70-
}
71-
7262
/// <inheritdoc />
7363
object? IChatClient.GetService(Type serviceType, object? serviceKey)
7464
{
@@ -321,7 +311,7 @@ private ChatCompletionsOptions ToAzureAIOptions(IEnumerable<ChatMessage> chatCon
321311
default:
322312
if (prop.Value is not null)
323313
{
324-
byte[] data = JsonSerializer.SerializeToUtf8Bytes(prop.Value, ToolCallJsonSerializerOptions.GetTypeInfo(typeof(object)));
314+
byte[] data = JsonSerializer.SerializeToUtf8Bytes(prop.Value, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object)));
325315
result.AdditionalProperties[prop.Key] = new BinaryData(data);
326316
}
327317

@@ -410,7 +400,7 @@ private static ChatCompletionsToolDefinition ToAzureAIChatTool(AIFunction aiFunc
410400
}
411401

412402
/// <summary>Converts an Extensions chat message enumerable to an AzureAI chat message enumerable.</summary>
413-
private IEnumerable<ChatRequestMessage> ToAzureAIInferenceChatMessages(IEnumerable<ChatMessage> inputs)
403+
private static IEnumerable<ChatRequestMessage> ToAzureAIInferenceChatMessages(IEnumerable<ChatMessage> inputs)
414404
{
415405
// Maps all of the M.E.AI types to the corresponding AzureAI types.
416406
// Unrecognized or non-processable content is ignored.
@@ -436,7 +426,7 @@ private IEnumerable<ChatRequestMessage> ToAzureAIInferenceChatMessages(IEnumerab
436426
{
437427
try
438428
{
439-
result = JsonSerializer.Serialize(resultContent.Result, ToolCallJsonSerializerOptions.GetTypeInfo(typeof(object)));
429+
result = JsonSerializer.Serialize(resultContent.Result, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object)));
440430
}
441431
catch (NotSupportedException)
442432
{
@@ -479,7 +469,7 @@ private IEnumerable<ChatRequestMessage> ToAzureAIInferenceChatMessages(IEnumerab
479469
callRequest.CallId,
480470
new FunctionCall(
481471
callRequest.Name,
482-
JsonSerializer.Serialize(callRequest.Arguments, ToolCallJsonSerializerOptions.GetTypeInfo(typeof(IDictionary<string, object>))))));
472+
JsonSerializer.Serialize(callRequest.Arguments, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(IDictionary<string, object>))))));
483473
}
484474
}
485475

src/Libraries/Microsoft.Extensions.AI.AzureAIInference/AzureAIInferenceEmbeddingGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace Microsoft.Extensions.AI;
2323

2424
/// <summary>Represents an <see cref="IEmbeddingGenerator{String, Embedding}"/> for an Azure.AI.Inference <see cref="EmbeddingsClient"/>.</summary>
25-
public sealed class AzureAIInferenceEmbeddingGenerator :
25+
internal sealed class AzureAIInferenceEmbeddingGenerator :
2626
IEmbeddingGenerator<string, Embedding<float>>
2727
{
2828
/// <summary>Metadata about the embedding generator.</summary>

src/Libraries/Microsoft.Extensions.AI.OpenAI/JsonModelHelpers.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ public static BinaryData Serialize<TModel>(TModel value)
1818
return value.Write(ModelReaderWriterOptions.Json);
1919
}
2020

21-
public static TModel Deserialize<TModel>(BinaryData data)
22-
where TModel : IJsonModel<TModel>, new()
23-
{
24-
return JsonModelDeserializationWitness<TModel>.Value.Create(data, ModelReaderWriterOptions.Json);
25-
}
26-
2721
public static TModel Deserialize<TModel>(ref Utf8JsonReader reader)
2822
where TModel : IJsonModel<TModel>, new()
2923
{

0 commit comments

Comments
 (0)