From d7c2b831da0c6969083134539606a4d99629217a Mon Sep 17 00:00:00 2001 From: m-nash <64171366+m-nash@users.noreply.github.com> Date: Tue, 28 Oct 2025 11:31:34 -0700 Subject: [PATCH] Fix custom code AOT compatibility --- src/Custom/Assistants/AssistantResponseFormat.cs | 2 +- src/Custom/FineTuning/FineTuningClient.cs | 2 +- src/Custom/FineTuning/FineTuningTrainingMethod.cs | 14 +++++++------- .../AsyncFineTuningCheckpointCollectionResult.cs | 2 +- .../AsyncFineTuningEventCollectionResult.cs | 2 +- .../FineTuningCheckpointCollectionResult.cs | 2 +- .../Pagination/FineTuningEventCollectionResult.cs | 2 +- src/Custom/Realtime/ConversationResponseOptions.cs | 4 ++-- src/Custom/Realtime/ConversationSessionOptions.cs | 4 ++-- .../Internal/InternalRealtimeResponseSession.cs | 2 +- src/Custom/Realtime/RealtimeSession.cs | 14 +++++++------- src/Custom/Realtime/Streaming/RealtimeUpdate.cs | 2 +- .../Internal/AsyncResponseItemCollectionResult.cs | 2 +- .../Internal/ResponseItemCollectionResult.cs | 2 +- .../Pagination/AsyncVectorStoreCollectionResult.cs | 2 +- .../Pagination/VectorStoreCollectionResult.cs | 2 +- src/Utility/CustomSerializationHelpers.cs | 2 +- 17 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Custom/Assistants/AssistantResponseFormat.cs b/src/Custom/Assistants/AssistantResponseFormat.cs index e4f4ad369..08fb7938c 100644 --- a/src/Custom/Assistants/AssistantResponseFormat.cs +++ b/src/Custom/Assistants/AssistantResponseFormat.cs @@ -103,7 +103,7 @@ public override string ToString() } else { - return ModelReaderWriter.Write(this).ToString(); + return ModelReaderWriter.Write(this, ModelReaderWriterOptions.Json, OpenAIContext.Default).ToString(); } } } diff --git a/src/Custom/FineTuning/FineTuningClient.cs b/src/Custom/FineTuning/FineTuningClient.cs index 1d809f536..0ce18e299 100644 --- a/src/Custom/FineTuning/FineTuningClient.cs +++ b/src/Custom/FineTuning/FineTuningClient.cs @@ -217,7 +217,7 @@ internal virtual FineTuningJob CreateJobFromResponse(PipelineResponse response) internal virtual IEnumerable CreateJobsFromPageResponse(PipelineResponse response) { - InternalListPaginatedFineTuningJobsResponse jobs = ModelReaderWriter.Read(response.Content)!; + InternalListPaginatedFineTuningJobsResponse jobs = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return jobs.Data.Select(job => new FineTuningJob(Pipeline, _endpoint, job, response)); } } diff --git a/src/Custom/FineTuning/FineTuningTrainingMethod.cs b/src/Custom/FineTuning/FineTuningTrainingMethod.cs index 36532481c..bc54b2227 100644 --- a/src/Custom/FineTuning/FineTuningTrainingMethod.cs +++ b/src/Custom/FineTuning/FineTuningTrainingMethod.cs @@ -23,9 +23,9 @@ public static FineTuningTrainingMethod CreateSupervised( Kind = InternalFineTuneMethodType.Supervised, Supervised = new() { Hyperparameters = new() { - _BatchSize = batchSize is not null ? ModelReaderWriter.Write(batchSize) : null, - _NEpochs = epochCount is not null ? ModelReaderWriter.Write(epochCount) : null, - _LearningRateMultiplier = learningRate is not null ? ModelReaderWriter.Write(learningRate) : null, + _BatchSize = batchSize is not null ? ModelReaderWriter.Write(batchSize, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null, + _NEpochs = epochCount is not null ? ModelReaderWriter.Write(epochCount, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null, + _LearningRateMultiplier = learningRate is not null ? ModelReaderWriter.Write(learningRate, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null, }, }, }; @@ -42,10 +42,10 @@ public static FineTuningTrainingMethod CreateDirectPreferenceOptimization( Kind = InternalFineTuneMethodType.Dpo, Dpo = new() { Hyperparameters = new() { - _Beta = betaFactor is not null ? ModelReaderWriter.Write(betaFactor) : null, - _BatchSize = batchSize is not null ? ModelReaderWriter.Write(batchSize) : null, - _NEpochs = epochCount is not null ? ModelReaderWriter.Write(epochCount) : null, - _LearningRateMultiplier = learningRate is not null ? ModelReaderWriter.Write(learningRate) : null, + _Beta = betaFactor is not null ? ModelReaderWriter.Write(betaFactor, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null, + _BatchSize = batchSize is not null ? ModelReaderWriter.Write(batchSize, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null, + _NEpochs = epochCount is not null ? ModelReaderWriter.Write(epochCount, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null, + _LearningRateMultiplier = learningRate is not null ? ModelReaderWriter.Write(learningRate, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null, }, }, }; diff --git a/src/Custom/FineTuning/Internal/Pagination/AsyncFineTuningCheckpointCollectionResult.cs b/src/Custom/FineTuning/Internal/Pagination/AsyncFineTuningCheckpointCollectionResult.cs index 9e6ad5da5..b51c2df04 100644 --- a/src/Custom/FineTuning/Internal/Pagination/AsyncFineTuningCheckpointCollectionResult.cs +++ b/src/Custom/FineTuning/Internal/Pagination/AsyncFineTuningCheckpointCollectionResult.cs @@ -81,7 +81,7 @@ protected override IAsyncEnumerable GetValuesFromPageAsync Argument.AssertNotNull(page, nameof(page)); PipelineResponse response = page.GetRawResponse(); - InternalListFineTuningJobCheckpointsResponse list = ModelReaderWriter.Read(response.Content)!; + InternalListFineTuningJobCheckpointsResponse list = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return list.Data.ToAsyncEnumerable(_cancellationToken); } } diff --git a/src/Custom/FineTuning/Internal/Pagination/AsyncFineTuningEventCollectionResult.cs b/src/Custom/FineTuning/Internal/Pagination/AsyncFineTuningEventCollectionResult.cs index 9c39a244d..b9536d8eb 100644 --- a/src/Custom/FineTuning/Internal/Pagination/AsyncFineTuningEventCollectionResult.cs +++ b/src/Custom/FineTuning/Internal/Pagination/AsyncFineTuningEventCollectionResult.cs @@ -81,7 +81,7 @@ protected override IAsyncEnumerable GetValuesFromPageAsync(Clie Argument.AssertNotNull(page, nameof(page)); PipelineResponse response = page.GetRawResponse(); - InternalListFineTuningJobEventsResponse list = ModelReaderWriter.Read(response.Content)!; + InternalListFineTuningJobEventsResponse list = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return list.Data.ToAsyncEnumerable(_cancellationToken); } } diff --git a/src/Custom/FineTuning/Internal/Pagination/FineTuningCheckpointCollectionResult.cs b/src/Custom/FineTuning/Internal/Pagination/FineTuningCheckpointCollectionResult.cs index 70f45b46f..01d1e83a9 100644 --- a/src/Custom/FineTuning/Internal/Pagination/FineTuningCheckpointCollectionResult.cs +++ b/src/Custom/FineTuning/Internal/Pagination/FineTuningCheckpointCollectionResult.cs @@ -86,7 +86,7 @@ protected override IEnumerable GetValuesFromPage(ClientRes Argument.AssertNotNull(page, nameof(page)); PipelineResponse response = page.GetRawResponse(); - InternalListFineTuningJobCheckpointsResponse points = ModelReaderWriter.Read(response.Content)!; + InternalListFineTuningJobCheckpointsResponse points = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return points.Data; } } diff --git a/src/Custom/FineTuning/Internal/Pagination/FineTuningEventCollectionResult.cs b/src/Custom/FineTuning/Internal/Pagination/FineTuningEventCollectionResult.cs index c38c88ffc..9bbeeba94 100644 --- a/src/Custom/FineTuning/Internal/Pagination/FineTuningEventCollectionResult.cs +++ b/src/Custom/FineTuning/Internal/Pagination/FineTuningEventCollectionResult.cs @@ -86,7 +86,7 @@ protected override IEnumerable GetValuesFromPage(ClientResult p Argument.AssertNotNull(page, nameof(page)); PipelineResponse response = page.GetRawResponse(); - InternalListFineTuningJobEventsResponse events = ModelReaderWriter.Read(response.Content)!; + InternalListFineTuningJobEventsResponse events = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return events.Data; } } diff --git a/src/Custom/Realtime/ConversationResponseOptions.cs b/src/Custom/Realtime/ConversationResponseOptions.cs index ecd24b1c4..ff1363b54 100644 --- a/src/Custom/Realtime/ConversationResponseOptions.cs +++ b/src/Custom/Realtime/ConversationResponseOptions.cs @@ -35,7 +35,7 @@ public ConversationToolChoice ToolChoice set { _internalToolChoice = value is not null - ? ModelReaderWriter.Write(value) + ? ModelReaderWriter.Write(value, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null; } } @@ -48,7 +48,7 @@ public ConversationMaxTokensChoice MaxOutputTokens get => ConversationMaxTokensChoice.FromBinaryData(_maxResponseOutputTokens); set { - _maxResponseOutputTokens = value == null ? null : ModelReaderWriter.Write(value); + _maxResponseOutputTokens = value == null ? null : ModelReaderWriter.Write(value, ModelReaderWriterOptions.Json, OpenAIContext.Default); } } diff --git a/src/Custom/Realtime/ConversationSessionOptions.cs b/src/Custom/Realtime/ConversationSessionOptions.cs index 524dcfd25..97331628a 100644 --- a/src/Custom/Realtime/ConversationSessionOptions.cs +++ b/src/Custom/Realtime/ConversationSessionOptions.cs @@ -33,7 +33,7 @@ public ConversationToolChoice ToolChoice set { _internalToolChoice = value is not null - ? ModelReaderWriter.Write(value) + ? ModelReaderWriter.Write(value, ModelReaderWriterOptions.Json, OpenAIContext.Default) : null; } } @@ -46,7 +46,7 @@ public ConversationMaxTokensChoice MaxOutputTokens get => ConversationMaxTokensChoice.FromBinaryData(_maxResponseOutputTokens); set { - _maxResponseOutputTokens = value == null ? null : ModelReaderWriter.Write(value); + _maxResponseOutputTokens = value == null ? null : ModelReaderWriter.Write(value, ModelReaderWriterOptions.Json, OpenAIContext.Default); } } diff --git a/src/Custom/Realtime/Internal/InternalRealtimeResponseSession.cs b/src/Custom/Realtime/Internal/InternalRealtimeResponseSession.cs index f1aa3169c..a5a6a4e3e 100644 --- a/src/Custom/Realtime/Internal/InternalRealtimeResponseSession.cs +++ b/src/Custom/Realtime/Internal/InternalRealtimeResponseSession.cs @@ -22,7 +22,7 @@ public ConversationMaxTokensChoice MaxResponseOutputTokens get => ConversationMaxTokensChoice.FromBinaryData(_maxResponseOutputTokens); set { - _maxResponseOutputTokens = value == null ? null : ModelReaderWriter.Write(value); + _maxResponseOutputTokens = value == null ? null : ModelReaderWriter.Write(value, ModelReaderWriterOptions.Json, OpenAIContext.Default); } } } diff --git a/src/Custom/Realtime/RealtimeSession.cs b/src/Custom/Realtime/RealtimeSession.cs index 872ca3d2b..cfe76ebfb 100644 --- a/src/Custom/Realtime/RealtimeSession.cs +++ b/src/Custom/Realtime/RealtimeSession.cs @@ -72,7 +72,7 @@ public virtual async Task SendInputAudioAsync(Stream audio, CancellationToken ca ReadOnlyMemory audioMemory = buffer.AsMemory(0, bytesRead); BinaryData audioData = BinaryData.FromBytes(audioMemory); InternalRealtimeClientEventInputAudioBufferAppend internalCommand = new(audioData); - BinaryData requestData = ModelReaderWriter.Write(internalCommand); + BinaryData requestData = ModelReaderWriter.Write(internalCommand, ModelReaderWriterOptions.Json, OpenAIContext.Default); await SendCommandAsync(requestData, cancellationToken.ToRequestOptions()).ConfigureAwait(false); } } @@ -116,7 +116,7 @@ public virtual void SendInputAudio(Stream audio, CancellationToken cancellationT ReadOnlyMemory audioMemory = buffer.AsMemory(0, bytesRead); BinaryData audioData = BinaryData.FromBytes(audioMemory); InternalRealtimeClientEventInputAudioBufferAppend internalCommand = new(audioData); - BinaryData requestData = ModelReaderWriter.Write(internalCommand); + BinaryData requestData = ModelReaderWriter.Write(internalCommand, ModelReaderWriterOptions.Json, OpenAIContext.Default); SendCommand(requestData, cancellationToken.ToRequestOptions()); } } @@ -151,7 +151,7 @@ public virtual async Task SendInputAudioAsync(BinaryData audio, CancellationToke } // TODO: consider automatically limiting/breaking size of chunk (as with streaming) InternalRealtimeClientEventInputAudioBufferAppend internalCommand = new(audio); - BinaryData requestData = ModelReaderWriter.Write(internalCommand); + BinaryData requestData = ModelReaderWriter.Write(internalCommand, ModelReaderWriterOptions.Json, OpenAIContext.Default); await SendCommandAsync(requestData, cancellationToken.ToRequestOptions()).ConfigureAwait(false); } } @@ -174,7 +174,7 @@ public virtual void SendInputAudio(BinaryData audio, CancellationToken cancellat } // TODO: consider automatically limiting/breaking size of chunk (as with streaming) InternalRealtimeClientEventInputAudioBufferAppend internalCommand = new(audio); - BinaryData requestData = ModelReaderWriter.Write(internalCommand); + BinaryData requestData = ModelReaderWriter.Write(internalCommand, ModelReaderWriterOptions.Json, OpenAIContext.Default); SendCommand(requestData, cancellationToken.ToRequestOptions()); } } @@ -363,7 +363,7 @@ public virtual async IAsyncEnumerable ReceiveUpdatesAsync([Enume await foreach (ClientResult protocolEvent in ReceiveUpdatesAsync(cancellationToken.ToRequestOptions())) { using PipelineResponse response = protocolEvent.GetRawResponse(); - RealtimeUpdate nextUpdate = ModelReaderWriter.Read(response.Content); + RealtimeUpdate nextUpdate = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default); yield return nextUpdate; } } @@ -375,14 +375,14 @@ public virtual IEnumerable ReceiveUpdates(CancellationToken canc internal virtual async Task SendCommandAsync(InternalRealtimeClientEvent command, CancellationToken cancellationToken = default) { - BinaryData requestData = ModelReaderWriter.Write(command); + BinaryData requestData = ModelReaderWriter.Write(command, ModelReaderWriterOptions.Json, OpenAIContext.Default); RequestOptions cancellationOptions = cancellationToken.ToRequestOptions(); await SendCommandAsync(requestData, cancellationOptions).ConfigureAwait(false); } internal virtual void SendCommand(InternalRealtimeClientEvent command, CancellationToken cancellationToken = default) { - BinaryData requestData = ModelReaderWriter.Write(command); + BinaryData requestData = ModelReaderWriter.Write(command, ModelReaderWriterOptions.Json, OpenAIContext.Default); RequestOptions cancellationOptions = cancellationToken.ToRequestOptions(); SendCommand(requestData, cancellationOptions); } diff --git a/src/Custom/Realtime/Streaming/RealtimeUpdate.cs b/src/Custom/Realtime/Streaming/RealtimeUpdate.cs index 7c7254155..d04888e4c 100644 --- a/src/Custom/Realtime/Streaming/RealtimeUpdate.cs +++ b/src/Custom/Realtime/Streaming/RealtimeUpdate.cs @@ -10,5 +10,5 @@ namespace OpenAI.Realtime; [CodeGenVisibility(nameof(Kind), CodeGenVisibility.Public)] public partial class RealtimeUpdate { - public BinaryData GetRawContent() => ModelReaderWriter.Write(this); + public BinaryData GetRawContent() => ModelReaderWriter.Write(this, ModelReaderWriterOptions.Json, OpenAIContext.Default); } \ No newline at end of file diff --git a/src/Custom/Responses/Pagination/Internal/AsyncResponseItemCollectionResult.cs b/src/Custom/Responses/Pagination/Internal/AsyncResponseItemCollectionResult.cs index a1ce3460d..259fd0433 100644 --- a/src/Custom/Responses/Pagination/Internal/AsyncResponseItemCollectionResult.cs +++ b/src/Custom/Responses/Pagination/Internal/AsyncResponseItemCollectionResult.cs @@ -53,7 +53,7 @@ protected override IAsyncEnumerable GetValuesFromPageAsync(ClientR Argument.AssertNotNull(page, nameof(page)); PipelineResponse response = page.GetRawResponse(); - InternalResponseItemList list = ModelReaderWriter.Read(response.Content)!; + InternalResponseItemList list = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return list.Data.ToAsyncEnumerable(_options?.CancellationToken ?? default); } diff --git a/src/Custom/Responses/Pagination/Internal/ResponseItemCollectionResult.cs b/src/Custom/Responses/Pagination/Internal/ResponseItemCollectionResult.cs index 1b143ecc3..98dbbdbbf 100644 --- a/src/Custom/Responses/Pagination/Internal/ResponseItemCollectionResult.cs +++ b/src/Custom/Responses/Pagination/Internal/ResponseItemCollectionResult.cs @@ -51,7 +51,7 @@ protected override IEnumerable GetValuesFromPage(ClientResult page Argument.AssertNotNull(page, nameof(page)); PipelineResponse response = page.GetRawResponse(); - InternalResponseItemList list = ModelReaderWriter.Read(response.Content)!; + InternalResponseItemList list = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return list.Data; } diff --git a/src/Custom/VectorStores/Internal/Pagination/AsyncVectorStoreCollectionResult.cs b/src/Custom/VectorStores/Internal/Pagination/AsyncVectorStoreCollectionResult.cs index 9eb429289..450c68c96 100644 --- a/src/Custom/VectorStores/Internal/Pagination/AsyncVectorStoreCollectionResult.cs +++ b/src/Custom/VectorStores/Internal/Pagination/AsyncVectorStoreCollectionResult.cs @@ -52,7 +52,7 @@ public async override IAsyncEnumerable GetRawPagesAsync() protected override IAsyncEnumerable GetValuesFromPageAsync(ClientResult page) { PipelineResponse response = page.GetRawResponse(); - InternalListVectorStoresResponse list = ModelReaderWriter.Read(response.Content)!; + InternalListVectorStoresResponse list = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return list.Data.ToAsyncEnumerable(_cancellationToken); } diff --git a/src/Custom/VectorStores/Internal/Pagination/VectorStoreCollectionResult.cs b/src/Custom/VectorStores/Internal/Pagination/VectorStoreCollectionResult.cs index f8faf783f..b15a30d77 100644 --- a/src/Custom/VectorStores/Internal/Pagination/VectorStoreCollectionResult.cs +++ b/src/Custom/VectorStores/Internal/Pagination/VectorStoreCollectionResult.cs @@ -50,7 +50,7 @@ protected override IEnumerable GetValuesFromPage(ClientResult page) Argument.AssertNotNull(page, nameof(page)); PipelineResponse response = page.GetRawResponse(); - InternalListVectorStoresResponse list = ModelReaderWriter.Read(response.Content)!; + InternalListVectorStoresResponse list = ModelReaderWriter.Read(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!; return list.Data; } diff --git a/src/Utility/CustomSerializationHelpers.cs b/src/Utility/CustomSerializationHelpers.cs index ce7b1d7f0..800e3ee0d 100644 --- a/src/Utility/CustomSerializationHelpers.cs +++ b/src/Utility/CustomSerializationHelpers.cs @@ -76,7 +76,7 @@ internal static BinaryData SerializeInstance( { options ??= new("W"); AssertSupportedPersistableWriteFormat(instance, options); - return ModelReaderWriter.Write(instance, options); + return ModelReaderWriter.Write(instance, options, OpenAIContext.Default); } internal static BinaryData SerializeInstance(T instance, ModelReaderWriterOptions options)