Skip to content
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
2 changes: 1 addition & 1 deletion src/Custom/Assistants/AssistantResponseFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public override string ToString()
}
else
{
return ModelReaderWriter.Write(this).ToString();
return ModelReaderWriter.Write(this, ModelReaderWriterOptions.Json, OpenAIContext.Default).ToString();
}
}
}
2 changes: 1 addition & 1 deletion src/Custom/FineTuning/FineTuningClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ internal virtual FineTuningJob CreateJobFromResponse(PipelineResponse response)

internal virtual IEnumerable<FineTuningJob> CreateJobsFromPageResponse(PipelineResponse response)
{
InternalListPaginatedFineTuningJobsResponse jobs = ModelReaderWriter.Read<InternalListPaginatedFineTuningJobsResponse>(response.Content)!;
InternalListPaginatedFineTuningJobsResponse jobs = ModelReaderWriter.Read<InternalListPaginatedFineTuningJobsResponse>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
return jobs.Data.Select(job => new FineTuningJob(Pipeline, _endpoint, job, response));
}
}
14 changes: 7 additions & 7 deletions src/Custom/FineTuning/FineTuningTrainingMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
};
Expand All @@ -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,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected override IAsyncEnumerable<FineTuningCheckpoint> GetValuesFromPageAsync
Argument.AssertNotNull(page, nameof(page));

PipelineResponse response = page.GetRawResponse();
InternalListFineTuningJobCheckpointsResponse list = ModelReaderWriter.Read<InternalListFineTuningJobCheckpointsResponse>(response.Content)!;
InternalListFineTuningJobCheckpointsResponse list = ModelReaderWriter.Read<InternalListFineTuningJobCheckpointsResponse>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
return list.Data.ToAsyncEnumerable(_cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected override IAsyncEnumerable<FineTuningEvent> GetValuesFromPageAsync(Clie
Argument.AssertNotNull(page, nameof(page));

PipelineResponse response = page.GetRawResponse();
InternalListFineTuningJobEventsResponse list = ModelReaderWriter.Read<InternalListFineTuningJobEventsResponse>(response.Content)!;
InternalListFineTuningJobEventsResponse list = ModelReaderWriter.Read<InternalListFineTuningJobEventsResponse>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
return list.Data.ToAsyncEnumerable(_cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override IEnumerable<FineTuningCheckpoint> GetValuesFromPage(ClientRes
Argument.AssertNotNull(page, nameof(page));

PipelineResponse response = page.GetRawResponse();
InternalListFineTuningJobCheckpointsResponse points = ModelReaderWriter.Read<InternalListFineTuningJobCheckpointsResponse>(response.Content)!;
InternalListFineTuningJobCheckpointsResponse points = ModelReaderWriter.Read<InternalListFineTuningJobCheckpointsResponse>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
return points.Data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override IEnumerable<FineTuningEvent> GetValuesFromPage(ClientResult p
Argument.AssertNotNull(page, nameof(page));

PipelineResponse response = page.GetRawResponse();
InternalListFineTuningJobEventsResponse events = ModelReaderWriter.Read<InternalListFineTuningJobEventsResponse>(response.Content)!;
InternalListFineTuningJobEventsResponse events = ModelReaderWriter.Read<InternalListFineTuningJobEventsResponse>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
return events.Data;
}
}
4 changes: 2 additions & 2 deletions src/Custom/Realtime/ConversationResponseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ConversationToolChoice ToolChoice
set
{
_internalToolChoice = value is not null
? ModelReaderWriter.Write(value)
? ModelReaderWriter.Write(value, ModelReaderWriterOptions.Json, OpenAIContext.Default)
: null;
}
}
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Custom/Realtime/ConversationSessionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ConversationToolChoice ToolChoice
set
{
_internalToolChoice = value is not null
? ModelReaderWriter.Write(value)
? ModelReaderWriter.Write(value, ModelReaderWriterOptions.Json, OpenAIContext.Default)
: null;
}
}
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
14 changes: 7 additions & 7 deletions src/Custom/Realtime/RealtimeSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public virtual async Task SendInputAudioAsync(Stream audio, CancellationToken ca
ReadOnlyMemory<byte> 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);
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public virtual void SendInputAudio(Stream audio, CancellationToken cancellationT
ReadOnlyMemory<byte> 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());
}
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -363,7 +363,7 @@ public virtual async IAsyncEnumerable<RealtimeUpdate> ReceiveUpdatesAsync([Enume
await foreach (ClientResult protocolEvent in ReceiveUpdatesAsync(cancellationToken.ToRequestOptions()))
{
using PipelineResponse response = protocolEvent.GetRawResponse();
RealtimeUpdate nextUpdate = ModelReaderWriter.Read<RealtimeUpdate>(response.Content);
RealtimeUpdate nextUpdate = ModelReaderWriter.Read<RealtimeUpdate>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default);
yield return nextUpdate;
}
}
Expand All @@ -375,14 +375,14 @@ public virtual IEnumerable<RealtimeUpdate> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Custom/Realtime/Streaming/RealtimeUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override IAsyncEnumerable<ResponseItem> GetValuesFromPageAsync(ClientR
Argument.AssertNotNull(page, nameof(page));

PipelineResponse response = page.GetRawResponse();
InternalResponseItemList list = ModelReaderWriter.Read<InternalResponseItemList>(response.Content)!;
InternalResponseItemList list = ModelReaderWriter.Read<InternalResponseItemList>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that the following four internal classes edited in this PR are actually not used anymore, and that they are leftovers from a previous PR where they should have been deleted instead:

  • ResponseItemCollectionResult
  • AsyncResponseItemCollectionResult
  • VectorStoreCollectionResult
  • AsyncVectorStoreCollectionResult

return list.Data.ToAsyncEnumerable(_options?.CancellationToken ?? default);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override IEnumerable<ResponseItem> GetValuesFromPage(ClientResult page
Argument.AssertNotNull(page, nameof(page));

PipelineResponse response = page.GetRawResponse();
InternalResponseItemList list = ModelReaderWriter.Read<InternalResponseItemList>(response.Content)!;
InternalResponseItemList list = ModelReaderWriter.Read<InternalResponseItemList>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
return list.Data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async override IAsyncEnumerable<ClientResult> GetRawPagesAsync()
protected override IAsyncEnumerable<VectorStore> GetValuesFromPageAsync(ClientResult page)
{
PipelineResponse response = page.GetRawResponse();
InternalListVectorStoresResponse list = ModelReaderWriter.Read<InternalListVectorStoresResponse>(response.Content)!;
InternalListVectorStoresResponse list = ModelReaderWriter.Read<InternalListVectorStoresResponse>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
return list.Data.ToAsyncEnumerable(_cancellationToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override IEnumerable<VectorStore> GetValuesFromPage(ClientResult page)
Argument.AssertNotNull(page, nameof(page));

PipelineResponse response = page.GetRawResponse();
InternalListVectorStoresResponse list = ModelReaderWriter.Read<InternalListVectorStoresResponse>(response.Content)!;
InternalListVectorStoresResponse list = ModelReaderWriter.Read<InternalListVectorStoresResponse>(response.Content, ModelReaderWriterOptions.Json, OpenAIContext.Default)!;
return list.Data;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Utility/CustomSerializationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal static BinaryData SerializeInstance<TOutput, UInstanceInput>(
{
options ??= new("W");
AssertSupportedPersistableWriteFormat<TOutput, UInstanceInput>(instance, options);
return ModelReaderWriter.Write(instance, options);
return ModelReaderWriter.Write(instance, options, OpenAIContext.Default);
}

internal static BinaryData SerializeInstance<T>(T instance, ModelReaderWriterOptions options)
Expand Down