diff --git a/CHANGELOG.md b/CHANGELOG.md index d6940c24f..692161c3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,14 @@ - Updated fine-tuning pagination methods `GetJobs`, `GetEvents`, and `GetJobCheckpoints` to return `IEnumerable` instead of `ClientResult`. (commit_hash) - Updated the batching pagination method `GetBatches` to return `IEnumerable` instead of `ClientResult`. (commit_hash) - Changed `GeneratedSpeechVoice` from an enum to an "extensible enum". (commit_hash) +- Changed `GeneratedSpeechFormat` from an enum to an "extensible enum". (commit_hash) +- Renamed `SpeechGenerationOptions`'s `Speed` property to `SpeedRatio`. (commit_hash) ### Bugs Fixed +- Corrected an internal deserialization issue that caused recent updates to Assistants `file_search` to fail when streaming a run. Strongly typed support for `ranking_options` is not included but will arrive soon. (commit_hash) +- Mitigated a .NET runtime issue that prevented `ChatResponseFormat` from serializing correct on targets including Unity. (commit_hash) + ### Other Changes - Reverted the removal of the version path parameter "v1" from the default endpoint URL. (commit_hash) diff --git a/api/OpenAI.netstandard2.0.cs b/api/OpenAI.netstandard2.0.cs index 87abb883d..26140d4b9 100644 --- a/api/OpenAI.netstandard2.0.cs +++ b/api/OpenAI.netstandard2.0.cs @@ -342,7 +342,7 @@ public class CodeInterpreterToolDefinition : ToolDefinition, IJsonModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class CodeInterpreterToolResources : IJsonModel, IPersistableModel { public IList FileIds { get; set; } @@ -359,7 +359,7 @@ public class FileSearchToolDefinition : ToolDefinition, IJsonModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class FileSearchToolResources : IJsonModel, IPersistableModel { public IList NewVectorStores { get; } @@ -382,7 +382,7 @@ public class FunctionToolDefinition : ToolDefinition, IJsonModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class MessageCollectionOptions { public string AfterId { get; set; } @@ -955,7 +955,7 @@ public abstract class ToolDefinition : IJsonModel, IPersistableM ToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class ToolOutput : IJsonModel, IPersistableModel { public ToolOutput(); @@ -1084,13 +1084,25 @@ public class AudioTranslationOptions : IJsonModel, IPer string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); } - public enum GeneratedSpeechFormat { - Mp3 = 0, - Opus = 1, - Aac = 2, - Flac = 3, - Wav = 4, - Pcm = 5 + public readonly partial struct GeneratedSpeechFormat : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public GeneratedSpeechFormat(string value); + public static GeneratedSpeechFormat Aac { get; } + public static GeneratedSpeechFormat Flac { get; } + public static GeneratedSpeechFormat Mp3 { get; } + public static GeneratedSpeechFormat Opus { get; } + public static GeneratedSpeechFormat Pcm { get; } + public static GeneratedSpeechFormat Wav { get; } + public readonly bool Equals(GeneratedSpeechFormat other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(GeneratedSpeechFormat left, GeneratedSpeechFormat right); + public static implicit operator GeneratedSpeechFormat(string value); + public static bool operator !=(GeneratedSpeechFormat left, GeneratedSpeechFormat right); + public override readonly string ToString(); } public readonly partial struct GeneratedSpeechVoice : IEquatable { private readonly object _dummy; @@ -1120,7 +1132,7 @@ public static class OpenAIAudioModelFactory { } public class SpeechGenerationOptions : IJsonModel, IPersistableModel { public GeneratedSpeechFormat? ResponseFormat { get; set; } - public float? Speed { get; set; } + public float? SpeedRatio { get; set; } SpeechGenerationOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); SpeechGenerationOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); @@ -1203,7 +1215,7 @@ public class AssistantChatMessage : ChatMessage, IJsonModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class ChatClient { protected ChatClient(); @@ -1335,7 +1347,7 @@ public abstract class ChatMessage : IJsonModel, IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class ChatMessageContentPart : IJsonModel, IPersistableModel { public BinaryData ImageBytes { get; } @@ -1403,6 +1415,7 @@ public abstract class ChatResponseFormat : IEquatable, IJson [EditorBrowsable(EditorBrowsableState.Never)] bool IEquatable.Equals(ChatResponseFormat other); public override string ToString(); + protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class ChatTokenLogProbabilityInfo : IJsonModel, IPersistableModel { public float LogProbability { get; } @@ -1510,7 +1523,7 @@ public class FunctionChatMessage : ChatMessage, IJsonModel, FunctionChatMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public readonly partial struct ImageChatMessageContentPartDetail : IEquatable { private readonly object _dummy; @@ -1589,7 +1602,7 @@ public class SystemChatMessage : ChatMessage, IJsonModel, IPe SystemChatMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class ToolChatMessage : ChatMessage, IJsonModel, IPersistableModel { public ToolChatMessage(string toolCallId, params ChatMessageContentPart[] contentParts); @@ -1601,7 +1614,7 @@ public class ToolChatMessage : ChatMessage, IJsonModel, IPersis ToolChatMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class UserChatMessage : ChatMessage, IJsonModel, IPersistableModel { public UserChatMessage(params ChatMessageContentPart[] content); @@ -1613,7 +1626,7 @@ public class UserChatMessage : ChatMessage, IJsonModel, IPersis UserChatMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } } namespace OpenAI.Embeddings { diff --git a/examples/CombinationExamples.cs b/examples/CombinationExamples.cs index 7987d81f2..ffa800c34 100644 --- a/examples/CombinationExamples.cs +++ b/examples/CombinationExamples.cs @@ -53,7 +53,7 @@ public void AlpacaArtAssessor() GeneratedSpeechVoice.Fable, new SpeechGenerationOptions() { - Speed = 0.9f, + SpeedRatio = 0.9f, ResponseFormat = GeneratedSpeechFormat.Opus, }); FileInfo ttsFileInfo = new($"{chatCompletion.Id}.opus"); @@ -89,7 +89,7 @@ public async Task CuriousCreatureCreator() GeneratedSpeechVoice.Onyx, new SpeechGenerationOptions() { - Speed = 1.1f, + SpeedRatio = 1.1f, ResponseFormat = GeneratedSpeechFormat.Opus, }); _ = Task.Run(async () => @@ -136,7 +136,7 @@ public async Task CuriousCreatureCreator() GeneratedSpeechVoice.Fable, new SpeechGenerationOptions() { - Speed = 0.9f, + SpeedRatio = 0.9f, ResponseFormat = GeneratedSpeechFormat.Opus, }); FileInfo criticAudioFileInfo = new($"{criticalAppraisalResult.Value.Id}-appraisal.opus"); diff --git a/src/Custom/Assistants/CodeInterpreterToolDefinition.Serialization.cs b/src/Custom/Assistants/CodeInterpreterToolDefinition.Serialization.cs index eae645a69..8c89a3ff8 100644 --- a/src/Custom/Assistants/CodeInterpreterToolDefinition.Serialization.cs +++ b/src/Custom/Assistants/CodeInterpreterToolDefinition.Serialization.cs @@ -12,7 +12,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, Mode internal static void SerializeCodeInterpreterToolDefinition(CodeInterpreterToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("type"u8); diff --git a/src/Custom/Assistants/FileSearchToolDefinition.Serialization.cs b/src/Custom/Assistants/FileSearchToolDefinition.Serialization.cs index 36968d793..6e4f9a8a4 100644 --- a/src/Custom/Assistants/FileSearchToolDefinition.Serialization.cs +++ b/src/Custom/Assistants/FileSearchToolDefinition.Serialization.cs @@ -12,7 +12,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelRead internal static void SerializeFileSearchToolDefinition(FileSearchToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("type"u8); diff --git a/src/Custom/Assistants/FunctionToolDefinition.Serialization.cs b/src/Custom/Assistants/FunctionToolDefinition.Serialization.cs index 37506d837..81638da72 100644 --- a/src/Custom/Assistants/FunctionToolDefinition.Serialization.cs +++ b/src/Custom/Assistants/FunctionToolDefinition.Serialization.cs @@ -12,7 +12,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReader internal static void SerializeFunctionToolDefinition(FunctionToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("function"u8); diff --git a/src/Custom/Assistants/Internal/UnknownAssistantToolDefinition.Serialization.cs b/src/Custom/Assistants/Internal/UnknownAssistantToolDefinition.Serialization.cs index b990dcbad..59524b086 100644 --- a/src/Custom/Assistants/Internal/UnknownAssistantToolDefinition.Serialization.cs +++ b/src/Custom/Assistants/Internal/UnknownAssistantToolDefinition.Serialization.cs @@ -12,7 +12,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOp internal static void SerializeUnknownAssistantToolDefinition(UnknownAssistantToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("type"u8); diff --git a/src/Custom/Assistants/ToolDefinition.Serialization.cs b/src/Custom/Assistants/ToolDefinition.Serialization.cs index 629e0f53b..3f69a6a7c 100644 --- a/src/Custom/Assistants/ToolDefinition.Serialization.cs +++ b/src/Custom/Assistants/ToolDefinition.Serialization.cs @@ -12,5 +12,5 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOp internal static void WriteCore(ToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } diff --git a/src/Custom/Audio/GeneratedSpeechFormat.cs b/src/Custom/Audio/GeneratedSpeechFormat.cs index 4ee71fef4..8ef097051 100644 --- a/src/Custom/Audio/GeneratedSpeechFormat.cs +++ b/src/Custom/Audio/GeneratedSpeechFormat.cs @@ -1,32 +1,7 @@ namespace OpenAI.Audio; -/// -/// Represents an audio data format available as either input or output into an audio operation. -/// +/// The audio format in which to generate the speech. [CodeGenModel("CreateSpeechRequestResponseFormat")] -public enum GeneratedSpeechFormat +public readonly partial struct GeneratedSpeechFormat { - /// MP3. /// - [CodeGenMember("Mp3")] - Mp3, - - /// Opus. /// - [CodeGenMember("Opus")] - Opus, - - /// AAC (advanced audio coding). /// - [CodeGenMember("Aac")] - Aac, - - /// FLAC (free lossless audio codec). /// - [CodeGenMember("Flac")] - Flac, - - /// WAV. /// - [CodeGenMember("Wav")] - Wav, - - /// PCM (pulse-code modulation). /// - [CodeGenMember("Pcm")] - Pcm, } \ No newline at end of file diff --git a/src/Custom/Audio/SpeechGenerationOptions.cs b/src/Custom/Audio/SpeechGenerationOptions.cs index 7c67060fa..387d3c5b2 100644 --- a/src/Custom/Audio/SpeechGenerationOptions.cs +++ b/src/Custom/Audio/SpeechGenerationOptions.cs @@ -1,9 +1,6 @@ namespace OpenAI.Audio; -/// -/// A representation of additional options available to control the behavior of a text-to-speech audio generation -/// operation. -/// +/// The options to configure text-to-speech audio generation. [CodeGenModel("CreateSpeechRequest")] [CodeGenSuppress("SpeechGenerationOptions", typeof(InternalCreateSpeechRequestModel), typeof(string), typeof(GeneratedSpeechVoice))] public partial class SpeechGenerationOptions @@ -11,23 +8,20 @@ public partial class SpeechGenerationOptions // CUSTOM: // - Made internal. The model is specified by the client. // - Added setter. - /// One of the available [TTS models](/docs/models/tts): `tts-1` or `tts-1-hd`. + [CodeGenMember("Model")] internal InternalCreateSpeechRequestModel Model { get; set; } // CUSTOM: // - Made internal. This value comes from a parameter on the client method. // - Added setter. /// The text to generate audio for. The maximum length is 4096 characters. + [CodeGenMember("Input")] internal string Input { get; set; } // CUSTOM: // - Made internal. This value comes from a parameter on the client method. // - Added setter. - /// - /// The voice to use when generating the audio. Supported voices are `alloy`, `echo`, `fable`, - /// `onyx`, `nova`, and `shimmer`. Previews of the voices are available in the - /// [Text to speech guide](/docs/guides/text-to-speech/voice-options). - /// + [CodeGenMember("Voice")] internal GeneratedSpeechVoice Voice { get; set; } // CUSTOM: Made public now that there are no required properties. @@ -35,4 +29,12 @@ public partial class SpeechGenerationOptions public SpeechGenerationOptions() { } + + // CUSTOM: Renamed. + /// + /// The speed of the generated audio expressed as a ratio between 0.5 and 2.0. The default is 1.0. + /// + [CodeGenMember("Speed")] + + public float? SpeedRatio { get; set; } } \ No newline at end of file diff --git a/src/Custom/Chat/AssistantChatMessage.Serialization.cs b/src/Custom/Chat/AssistantChatMessage.Serialization.cs index 44749c211..53faea0bb 100644 --- a/src/Custom/Chat/AssistantChatMessage.Serialization.cs +++ b/src/Custom/Chat/AssistantChatMessage.Serialization.cs @@ -1,6 +1,4 @@ using System.ClientModel.Primitives; -using System.Collections; -using System.Collections.Generic; using System.Text.Json; namespace OpenAI.Chat; @@ -14,7 +12,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWr internal static void SerializeAssistantChatMessage(AssistantChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("role"u8); diff --git a/src/Custom/Chat/ChatMessage.Serialization.cs b/src/Custom/Chat/ChatMessage.Serialization.cs index 007212010..39ea1f59d 100644 --- a/src/Custom/Chat/ChatMessage.Serialization.cs +++ b/src/Custom/Chat/ChatMessage.Serialization.cs @@ -43,5 +43,5 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptio internal static void WriteCore(ChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); + protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } diff --git a/src/Custom/Chat/ChatResponseFormat.Serialization.cs b/src/Custom/Chat/ChatResponseFormat.Serialization.cs new file mode 100644 index 000000000..80372fd43 --- /dev/null +++ b/src/Custom/Chat/ChatResponseFormat.Serialization.cs @@ -0,0 +1,19 @@ +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Text.Json; + +namespace OpenAI.Chat; + +[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))] +public abstract partial class ChatResponseFormat : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, WriteCore, writer, options); + + internal static void WriteCore(ChatResponseFormat instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + => instance.WriteCore(writer, options); + + protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); +} diff --git a/src/Custom/Chat/ChatResponseFormat.cs b/src/Custom/Chat/ChatResponseFormat.cs index 2b7feb1b8..cf4e5d783 100644 --- a/src/Custom/Chat/ChatResponseFormat.cs +++ b/src/Custom/Chat/ChatResponseFormat.cs @@ -5,19 +5,44 @@ namespace OpenAI.Chat; +/// +/// The format that the model should output. +/// +/// +/// Call to create a requesting plain +/// text. +/// +/// +/// Call to create a requesting +/// valid JSON, a.k.a. JSON mode. +/// +/// +/// Call to create a +/// requesting adherence to the specified JSON schema, +/// a.k.a. structured outputs. +/// +/// +/// [CodeGenModel("ChatResponseFormat")] public abstract partial class ChatResponseFormat : IEquatable { + /// Creates a new requesting plain text. public static ChatResponseFormat Text { get; } = new InternalChatResponseFormatText(); + + /// Creates a new requesting valid JSON, a.k.a. JSON mode. public static ChatResponseFormat JsonObject { get; } = new InternalChatResponseFormatJsonObject(); + /// Creates a new requesting plain text. public static ChatResponseFormat CreateTextFormat() => new InternalChatResponseFormatText(); + + /// Creates a new requesting valid JSON, a.k.a. JSON mode. public static ChatResponseFormat CreateJsonObjectFormat() => new InternalChatResponseFormatJsonObject(); - public static ChatResponseFormat CreateJsonSchemaFormat( - string name, - BinaryData jsonSchema, - string description = null, - bool? strictSchemaEnabled = null) + + /// + /// Creates a new requesting adherence to the specified JSON schema, + /// a.k.a. structured outputs. + /// + public static ChatResponseFormat CreateJsonSchemaFormat(string name, BinaryData jsonSchema, string description = null, bool? strictSchemaEnabled = null) { Argument.AssertNotNullOrEmpty(name, nameof(name)); Argument.AssertNotNull(jsonSchema, nameof(jsonSchema)); @@ -27,7 +52,8 @@ public static ChatResponseFormat CreateJsonSchemaFormat( name, jsonSchema, strictSchemaEnabled, - null); + serializedAdditionalRawData: null); + return new InternalChatResponseFormatJsonSchema(internalSchema); } @@ -38,6 +64,7 @@ public static ChatResponseFormat CreateJsonSchemaFormat( { return second is null; } + return first.Equals(second); } diff --git a/src/Custom/Chat/FunctionChatMessage.Serialization.cs b/src/Custom/Chat/FunctionChatMessage.Serialization.cs index 0bf7c4b18..b63581413 100644 --- a/src/Custom/Chat/FunctionChatMessage.Serialization.cs +++ b/src/Custom/Chat/FunctionChatMessage.Serialization.cs @@ -16,7 +16,7 @@ internal static void SerializeFunctionChatMessage(FunctionChatMessage instance, instance.WriteCore(writer, options); } - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("role"u8); diff --git a/src/Custom/Chat/Internal/GeneratorStubs.cs b/src/Custom/Chat/Internal/GeneratorStubs.cs index f52ceaa79..87294c512 100644 --- a/src/Custom/Chat/Internal/GeneratorStubs.cs +++ b/src/Custom/Chat/Internal/GeneratorStubs.cs @@ -57,9 +57,18 @@ internal readonly partial struct InternalCreateChatCompletionFunctionResponseCho [CodeGenModel("CreateChatCompletionFunctionResponseObject")] internal readonly partial struct InternalCreateChatCompletionFunctionResponseObject { } +[CodeGenModel("ChatCompletionRequestMessageContentPartRefusal")] +internal partial class InternalChatCompletionRequestMessageContentPartRefusal { } + +[CodeGenModel("ChatCompletionRequestMessageContentPartRefusalType")] +internal readonly partial struct InternalChatCompletionRequestMessageContentPartRefusalType { } + [CodeGenModel("CreateChatCompletionRequestModel")] internal readonly partial struct InternalCreateChatCompletionRequestModel { } +[CodeGenModel("CreateChatCompletionRequestServiceTier")] +internal readonly partial struct InternalCreateChatCompletionRequestServiceTier { } + [CodeGenModel("CreateChatCompletionRequestToolChoice")] internal readonly partial struct InternalCreateChatCompletionRequestToolChoice { } @@ -72,6 +81,9 @@ internal partial class InternalCreateChatCompletionResponseChoiceLogprobs { } [CodeGenModel("CreateChatCompletionResponseObject")] internal readonly partial struct InternalCreateChatCompletionResponseObject { } +[CodeGenModel("CreateChatCompletionResponseServiceTier")] +internal readonly partial struct InternalCreateChatCompletionResponseServiceTier { } + [CodeGenModel("CreateChatCompletionStreamResponseChoice")] internal partial class InternalCreateChatCompletionStreamResponseChoice { } @@ -84,18 +96,11 @@ internal partial class InternalCreateChatCompletionStreamResponseChoiceLogprobs [CodeGenModel("CreateChatCompletionStreamResponseObject")] internal readonly partial struct InternalCreateChatCompletionStreamResponseObject { } +[CodeGenModel("CreateChatCompletionStreamResponseServiceTier")] +internal readonly partial struct InternalCreateChatCompletionStreamResponseServiceTier { } + [CodeGenModel("CreateChatCompletionStreamResponseUsage")] internal partial class InternalCreateChatCompletionStreamResponseUsage { } [CodeGenModel("FunctionParameters")] internal partial class InternalFunctionParameters { } - -[CodeGenModel("ChatResponseFormatText")] internal partial class InternalChatResponseFormatText { } -[CodeGenModel("ChatResponseFormatJsonObject")] internal partial class InternalChatResponseFormatJsonObject { } -[CodeGenModel("ChatResponseFormatJsonSchema")] internal partial class InternalChatResponseFormatJsonSchema { } -[CodeGenModel("UnknownChatResponseFormat")] internal partial class InternalUnknownChatResponseFormat { } -[CodeGenModel("ChatCompletionRequestMessageContentPartRefusal")] internal partial class InternalChatCompletionRequestMessageContentPartRefusal { } -[CodeGenModel("ChatCompletionRequestMessageContentPartRefusalType")] internal readonly partial struct InternalChatCompletionRequestMessageContentPartRefusalType { } -[CodeGenModel("CreateChatCompletionRequestServiceTier")] internal readonly partial struct InternalCreateChatCompletionRequestServiceTier { } -[CodeGenModel("CreateChatCompletionResponseServiceTier")] internal readonly partial struct InternalCreateChatCompletionResponseServiceTier { } -[CodeGenModel("CreateChatCompletionStreamResponseServiceTier")] internal readonly partial struct InternalCreateChatCompletionStreamResponseServiceTier { } diff --git a/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.Serialization.cs b/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.Serialization.cs new file mode 100644 index 000000000..0e6b09480 --- /dev/null +++ b/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.Serialization.cs @@ -0,0 +1,44 @@ +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.Chat; + +[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))] +internal partial class InternalChatResponseFormatJsonObject : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeInternalChatResponseFormatJsonObject, writer, options); + + internal static void SerializeInternalChatResponseFormatJsonObject(InternalChatResponseFormatJsonObject instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + => instance.WriteCore(writer, options); + + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } +} diff --git a/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.cs b/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.cs new file mode 100644 index 000000000..f161ae7a8 --- /dev/null +++ b/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.cs @@ -0,0 +1,6 @@ +namespace OpenAI.Chat; + +[CodeGenModel("ChatResponseFormatJsonObject")] +internal partial class InternalChatResponseFormatJsonObject +{ +} \ No newline at end of file diff --git a/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.Serialization.cs b/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.Serialization.cs new file mode 100644 index 000000000..ee171b4d7 --- /dev/null +++ b/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.Serialization.cs @@ -0,0 +1,49 @@ +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.Chat; + +[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))] +internal partial class InternalChatResponseFormatJsonSchema : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeInternalChatResponseFormatJsonSchema, writer, options); + + internal static void SerializeInternalChatResponseFormatJsonSchema(InternalChatResponseFormatJsonSchema instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + => instance.WriteCore(writer, options); + + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("json_schema") != true) + { + writer.WritePropertyName("json_schema"u8); + writer.WriteObjectValue(JsonSchema, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } +} diff --git a/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.cs b/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.cs new file mode 100644 index 000000000..cd9e63b5a --- /dev/null +++ b/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.cs @@ -0,0 +1,11 @@ +using System.ClientModel.Primitives; +using System.Data; +using System.Text.Json; +using System; + +namespace OpenAI.Chat; + +[CodeGenModel("ChatResponseFormatJsonSchema")] +internal partial class InternalChatResponseFormatJsonSchema +{ +} \ No newline at end of file diff --git a/src/Custom/Chat/Internal/InternalChatResponseFormatText.Serialization.cs b/src/Custom/Chat/Internal/InternalChatResponseFormatText.Serialization.cs new file mode 100644 index 000000000..30f5fe5ee --- /dev/null +++ b/src/Custom/Chat/Internal/InternalChatResponseFormatText.Serialization.cs @@ -0,0 +1,44 @@ +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.Chat; + +[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))] +internal partial class InternalChatResponseFormatText : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeInternalChatResponseFormatText, writer, options); + + internal static void SerializeInternalChatResponseFormatText(InternalChatResponseFormatText instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + => instance.WriteCore(writer, options); + + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } +} diff --git a/src/Custom/Chat/Internal/InternalChatResponseFormatText.cs b/src/Custom/Chat/Internal/InternalChatResponseFormatText.cs new file mode 100644 index 000000000..3df5a8bf5 --- /dev/null +++ b/src/Custom/Chat/Internal/InternalChatResponseFormatText.cs @@ -0,0 +1,6 @@ +namespace OpenAI.Chat; + +[CodeGenModel("ChatResponseFormatText")] +internal partial class InternalChatResponseFormatText +{ +} diff --git a/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs b/src/Custom/Chat/Internal/InternalUnknownChatMessage.Serialization.cs similarity index 77% rename from src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs rename to src/Custom/Chat/Internal/InternalUnknownChatMessage.Serialization.cs index aa3efbb42..a9575f0d1 100644 --- a/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs +++ b/src/Custom/Chat/Internal/InternalUnknownChatMessage.Serialization.cs @@ -6,17 +6,17 @@ namespace OpenAI.Chat; [CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))] -internal partial class UnknownChatMessage : IJsonModel +internal partial class InternalUnknownChatMessage : IJsonModel { void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - => CustomSerializationHelpers.SerializeInstance(this, WriteCore, writer, options); + => CustomSerializationHelpers.SerializeInstance(this, WriteCore, writer, options); - internal static void WriteCore(UnknownChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + internal static void WriteCore(InternalUnknownChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) { instance.WriteCore(writer, options); } - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("role"u8); @@ -26,7 +26,7 @@ protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOption writer.WriteEndObject(); } - internal static UnknownChatMessage DeserializeUnknownChatMessage(JsonElement element, ModelReaderWriterOptions options = null) + internal static InternalUnknownChatMessage DeserializeUnknownChatMessage(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -65,6 +65,6 @@ internal static UnknownChatMessage DeserializeUnknownChatMessage(JsonElement ele } } serializedAdditionalRawData = rawDataDictionary; - return new UnknownChatMessage(role.Value, content ?? new ChangeTrackingList(), serializedAdditionalRawData); + return new InternalUnknownChatMessage(role.Value, content ?? new ChangeTrackingList(), serializedAdditionalRawData); } } diff --git a/src/Custom/Chat/Internal/UnknownChatMessage.cs b/src/Custom/Chat/Internal/InternalUnknownChatMessage.cs similarity index 56% rename from src/Custom/Chat/Internal/UnknownChatMessage.cs rename to src/Custom/Chat/Internal/InternalUnknownChatMessage.cs index ac4faf00f..cb046b82e 100644 --- a/src/Custom/Chat/Internal/UnknownChatMessage.cs +++ b/src/Custom/Chat/Internal/InternalUnknownChatMessage.cs @@ -1,7 +1,7 @@ namespace OpenAI.Chat; [CodeGenModel("UnknownChatCompletionRequestMessage")] -internal partial class UnknownChatMessage : ChatMessage +internal partial class InternalUnknownChatMessage : ChatMessage { } \ No newline at end of file diff --git a/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.Serialization.cs b/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.Serialization.cs new file mode 100644 index 000000000..f64b69738 --- /dev/null +++ b/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.Serialization.cs @@ -0,0 +1,44 @@ +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.Chat; + +[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))] +internal partial class InternalUnknownChatResponseFormat : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeChatResponseFormat, writer, options); + + internal static void SerializeChatResponseFormat(InternalUnknownChatResponseFormat instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + => instance.WriteCore(writer, options); + + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } +} diff --git a/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.cs b/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.cs new file mode 100644 index 000000000..b869078fc --- /dev/null +++ b/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.cs @@ -0,0 +1,6 @@ +namespace OpenAI.Chat; + +[CodeGenModel("UnknownChatResponseFormat")] +internal partial class InternalUnknownChatResponseFormat +{ +} \ No newline at end of file diff --git a/src/Custom/Chat/Internal/AsyncStreamingChatCompletionUpdateCollection.cs b/src/Custom/Chat/Internal/Streaming/AsyncStreamingChatCompletionUpdateCollection.cs similarity index 100% rename from src/Custom/Chat/Internal/AsyncStreamingChatCompletionUpdateCollection.cs rename to src/Custom/Chat/Internal/Streaming/AsyncStreamingChatCompletionUpdateCollection.cs diff --git a/src/Custom/Chat/Internal/StreamingChatCompletionUpdateCollection.cs b/src/Custom/Chat/Internal/Streaming/StreamingChatCompletionUpdateCollection.cs similarity index 100% rename from src/Custom/Chat/Internal/StreamingChatCompletionUpdateCollection.cs rename to src/Custom/Chat/Internal/Streaming/StreamingChatCompletionUpdateCollection.cs diff --git a/src/Custom/Chat/SystemChatMessage.Serialization.cs b/src/Custom/Chat/SystemChatMessage.Serialization.cs index b1063b03f..3e02bd8e3 100644 --- a/src/Custom/Chat/SystemChatMessage.Serialization.cs +++ b/src/Custom/Chat/SystemChatMessage.Serialization.cs @@ -14,7 +14,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWrite internal static void SerializeSystemChatMessage(SystemChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("role"u8); diff --git a/src/Custom/Chat/ToolChatMessage.Serialization.cs b/src/Custom/Chat/ToolChatMessage.Serialization.cs index 9eb64d17e..6c4edc3b5 100644 --- a/src/Custom/Chat/ToolChatMessage.Serialization.cs +++ b/src/Custom/Chat/ToolChatMessage.Serialization.cs @@ -12,7 +12,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO internal static void SerializeToolChatMessage(ToolChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("role"u8); diff --git a/src/Custom/Chat/UserChatMessage.Serialization.cs b/src/Custom/Chat/UserChatMessage.Serialization.cs index fcd98a834..dd8c689f1 100644 --- a/src/Custom/Chat/UserChatMessage.Serialization.cs +++ b/src/Custom/Chat/UserChatMessage.Serialization.cs @@ -14,7 +14,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO internal static void SerializeUserChatMessage(UserChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) => instance.WriteCore(writer, options); - protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); writer.WritePropertyName("role"u8); diff --git a/src/Custom/Common/Internal/GeneratorStubs.cs b/src/Custom/Common/Internal/GeneratorStubs.cs index d0c7de7f2..a6172b6ac 100644 --- a/src/Custom/Common/Internal/GeneratorStubs.cs +++ b/src/Custom/Common/Internal/GeneratorStubs.cs @@ -1,11 +1,19 @@ -using System; - namespace OpenAI.Internal; -[CodeGenModel("OmniTypedResponseFormat")] internal partial class InternalOmniTypedResponseFormat { } -[CodeGenModel("ResponseFormatJsonObject")] internal partial class InternalResponseFormatJsonObject { } -[CodeGenModel("ResponseFormatJsonSchema")] internal partial class InternalResponseFormatJsonSchema { } -[CodeGenModel("ResponseFormatJsonSchemaJsonSchema")] internal partial class InternalResponseFormatJsonSchemaJsonSchema { [CodeGenMember("Schema")] public BinaryData Schema { get; set; } } -[CodeGenModel("ResponseFormatJsonSchemaSchema")] internal partial class InternalResponseFormatJsonSchemaSchema { } -[CodeGenModel("ResponseFormatText")] internal partial class InternalResponseFormatText { } -[CodeGenModel("UnknownOmniTypedResponseFormat")] internal partial class InternalUnknownOmniTypedResponseFormat { } +[CodeGenModel("OmniTypedResponseFormat")] +internal partial class InternalOmniTypedResponseFormat { } + +[CodeGenModel("ResponseFormatJsonObject")] +internal partial class InternalResponseFormatJsonObject { } + +[CodeGenModel("ResponseFormatJsonSchema")] +internal partial class InternalResponseFormatJsonSchema { } + +[CodeGenModel("ResponseFormatJsonSchemaSchema")] +internal partial class InternalResponseFormatJsonSchemaSchema { } + +[CodeGenModel("ResponseFormatText")] +internal partial class InternalResponseFormatText { } + +[CodeGenModel("UnknownOmniTypedResponseFormat")] +internal partial class InternalUnknownOmniTypedResponseFormat { } diff --git a/src/Custom/Common/Internal/InternalResponseFormatJsonSchemaJsonSchema.cs b/src/Custom/Common/Internal/InternalResponseFormatJsonSchemaJsonSchema.cs new file mode 100644 index 000000000..7fa1d70fd --- /dev/null +++ b/src/Custom/Common/Internal/InternalResponseFormatJsonSchemaJsonSchema.cs @@ -0,0 +1,10 @@ +using System; + +namespace OpenAI.Internal; + +[CodeGenModel("ResponseFormatJsonSchemaJsonSchema")] +internal partial class InternalResponseFormatJsonSchemaJsonSchema +{ + [CodeGenMember("Schema")] + public BinaryData Schema { get; set; } +} \ No newline at end of file diff --git a/src/Generated/Models/ChatMessage.Serialization.cs b/src/Generated/Models/ChatMessage.Serialization.cs index 3d13375d1..971105a95 100644 --- a/src/Generated/Models/ChatMessage.Serialization.cs +++ b/src/Generated/Models/ChatMessage.Serialization.cs @@ -10,7 +10,7 @@ namespace OpenAI.Chat { - [PersistableModelProxy(typeof(UnknownChatMessage))] + [PersistableModelProxy(typeof(InternalUnknownChatMessage))] public partial class ChatMessage : IJsonModel { ChatMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) @@ -45,7 +45,7 @@ internal static ChatMessage DeserializeChatMessage(JsonElement element, ModelRea case "user": return UserChatMessage.DeserializeUserChatMessage(element, options); } } - return UnknownChatMessage.DeserializeUnknownChatMessage(element, options); + return InternalUnknownChatMessage.DeserializeInternalUnknownChatMessage(element, options); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/src/Generated/Models/ChatResponseFormat.Serialization.cs b/src/Generated/Models/ChatResponseFormat.Serialization.cs index 2c055865b..26c297851 100644 --- a/src/Generated/Models/ChatResponseFormat.Serialization.cs +++ b/src/Generated/Models/ChatResponseFormat.Serialization.cs @@ -12,42 +12,6 @@ namespace OpenAI.Chat [PersistableModelProxy(typeof(InternalUnknownChatResponseFormat))] public partial class ChatResponseFormat : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ChatResponseFormat)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("type") != true) - { - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - ChatResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; diff --git a/src/Generated/Models/GeneratedSpeechFormat.Serialization.cs b/src/Generated/Models/GeneratedSpeechFormat.Serialization.cs deleted file mode 100644 index ff1d45f85..000000000 --- a/src/Generated/Models/GeneratedSpeechFormat.Serialization.cs +++ /dev/null @@ -1,33 +0,0 @@ -// - -#nullable disable - -using System; - -namespace OpenAI.Audio -{ - internal static partial class GeneratedSpeechFormatExtensions - { - public static string ToSerialString(this GeneratedSpeechFormat value) => value switch - { - GeneratedSpeechFormat.Mp3 => "mp3", - GeneratedSpeechFormat.Opus => "opus", - GeneratedSpeechFormat.Aac => "aac", - GeneratedSpeechFormat.Flac => "flac", - GeneratedSpeechFormat.Wav => "wav", - GeneratedSpeechFormat.Pcm => "pcm", - _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown GeneratedSpeechFormat value.") - }; - - public static GeneratedSpeechFormat ToGeneratedSpeechFormat(this string value) - { - if (StringComparer.OrdinalIgnoreCase.Equals(value, "mp3")) return GeneratedSpeechFormat.Mp3; - if (StringComparer.OrdinalIgnoreCase.Equals(value, "opus")) return GeneratedSpeechFormat.Opus; - if (StringComparer.OrdinalIgnoreCase.Equals(value, "aac")) return GeneratedSpeechFormat.Aac; - if (StringComparer.OrdinalIgnoreCase.Equals(value, "flac")) return GeneratedSpeechFormat.Flac; - if (StringComparer.OrdinalIgnoreCase.Equals(value, "wav")) return GeneratedSpeechFormat.Wav; - if (StringComparer.OrdinalIgnoreCase.Equals(value, "pcm")) return GeneratedSpeechFormat.Pcm; - throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown GeneratedSpeechFormat value."); - } - } -} diff --git a/src/Generated/Models/GeneratedSpeechFormat.cs b/src/Generated/Models/GeneratedSpeechFormat.cs new file mode 100644 index 000000000..e8c256e31 --- /dev/null +++ b/src/Generated/Models/GeneratedSpeechFormat.cs @@ -0,0 +1,44 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Audio +{ + public readonly partial struct GeneratedSpeechFormat : IEquatable + { + private readonly string _value; + + public GeneratedSpeechFormat(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string Mp3Value = "mp3"; + private const string OpusValue = "opus"; + private const string AacValue = "aac"; + private const string FlacValue = "flac"; + private const string WavValue = "wav"; + private const string PcmValue = "pcm"; + + public static GeneratedSpeechFormat Mp3 { get; } = new GeneratedSpeechFormat(Mp3Value); + public static GeneratedSpeechFormat Opus { get; } = new GeneratedSpeechFormat(OpusValue); + public static GeneratedSpeechFormat Aac { get; } = new GeneratedSpeechFormat(AacValue); + public static GeneratedSpeechFormat Flac { get; } = new GeneratedSpeechFormat(FlacValue); + public static GeneratedSpeechFormat Wav { get; } = new GeneratedSpeechFormat(WavValue); + public static GeneratedSpeechFormat Pcm { get; } = new GeneratedSpeechFormat(PcmValue); + public static bool operator ==(GeneratedSpeechFormat left, GeneratedSpeechFormat right) => left.Equals(right); + public static bool operator !=(GeneratedSpeechFormat left, GeneratedSpeechFormat right) => !left.Equals(right); + public static implicit operator GeneratedSpeechFormat(string value) => new GeneratedSpeechFormat(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is GeneratedSpeechFormat other && Equals(other); + public bool Equals(GeneratedSpeechFormat other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalBatchRequestOutputResponse.Serialization.cs b/src/Generated/Models/InternalBatchRequestOutputResponse.Serialization.cs index 54280475f..5f48d8090 100644 --- a/src/Generated/Models/InternalBatchRequestOutputResponse.Serialization.cs +++ b/src/Generated/Models/InternalBatchRequestOutputResponse.Serialization.cs @@ -38,7 +38,19 @@ void IJsonModel.Write(Utf8JsonWriter writer, foreach (var item in Body) { writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + if (item.Value == null) + { + writer.WriteNullValue(); + continue; + } +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif } writer.WriteEndObject(); } @@ -86,7 +98,7 @@ internal static InternalBatchRequestOutputResponse DeserializeInternalBatchReque } int? statusCode = default; string requestId = default; - IReadOnlyDictionary body = default; + IReadOnlyDictionary body = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -111,10 +123,17 @@ internal static InternalBatchRequestOutputResponse DeserializeInternalBatchReque { continue; } - Dictionary dictionary = new Dictionary(); + Dictionary dictionary = new Dictionary(); foreach (var property0 in property.Value.EnumerateObject()) { - dictionary.Add(property0.Name, property0.Value.GetString()); + if (property0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property0.Name, null); + } + else + { + dictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText())); + } } body = dictionary; continue; @@ -126,7 +145,7 @@ internal static InternalBatchRequestOutputResponse DeserializeInternalBatchReque } } serializedAdditionalRawData = rawDataDictionary; - return new InternalBatchRequestOutputResponse(statusCode, requestId, body ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); + return new InternalBatchRequestOutputResponse(statusCode, requestId, body ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/src/Generated/Models/InternalBatchRequestOutputResponse.cs b/src/Generated/Models/InternalBatchRequestOutputResponse.cs index 2919fec21..8435f20dc 100644 --- a/src/Generated/Models/InternalBatchRequestOutputResponse.cs +++ b/src/Generated/Models/InternalBatchRequestOutputResponse.cs @@ -12,10 +12,10 @@ internal partial class InternalBatchRequestOutputResponse internal IDictionary SerializedAdditionalRawData { get; set; } internal InternalBatchRequestOutputResponse() { - Body = new ChangeTrackingDictionary(); + Body = new ChangeTrackingDictionary(); } - internal InternalBatchRequestOutputResponse(int? statusCode, string requestId, IReadOnlyDictionary body, IDictionary serializedAdditionalRawData) + internal InternalBatchRequestOutputResponse(int? statusCode, string requestId, IReadOnlyDictionary body, IDictionary serializedAdditionalRawData) { StatusCode = statusCode; RequestId = requestId; @@ -25,6 +25,6 @@ internal InternalBatchRequestOutputResponse(int? statusCode, string requestId, I public int? StatusCode { get; } public string RequestId { get; } - public IReadOnlyDictionary Body { get; } + public IReadOnlyDictionary Body { get; } } } diff --git a/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs b/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs index 9c63f887b..3e555b657 100644 --- a/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs +++ b/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs @@ -12,42 +12,6 @@ namespace OpenAI.Chat { internal partial class InternalChatResponseFormatJsonObject : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonObject)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("type") != true) - { - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - InternalChatResponseFormatJsonObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; diff --git a/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs b/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs index c5c0cca64..c2b875ee6 100644 --- a/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs +++ b/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs @@ -13,47 +13,6 @@ namespace OpenAI.Chat { internal partial class InternalChatResponseFormatJsonSchema : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonSchema)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("json_schema") != true) - { - writer.WritePropertyName("json_schema"u8); - writer.WriteObjectValue(JsonSchema, options); - } - if (SerializedAdditionalRawData?.ContainsKey("type") != true) - { - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - InternalChatResponseFormatJsonSchema IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; diff --git a/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs b/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs index c0f373c9d..6ab2655f8 100644 --- a/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs +++ b/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs @@ -12,42 +12,6 @@ namespace OpenAI.Chat { internal partial class InternalChatResponseFormatText : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalChatResponseFormatText)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("type") != true) - { - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - InternalChatResponseFormatText IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; diff --git a/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.Serialization.cs b/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.Serialization.cs index e9dd186c0..78a34b22e 100644 --- a/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.Serialization.cs +++ b/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.Serialization.cs @@ -38,7 +38,19 @@ void IJsonModel.Write( foreach (var item in FileSearch) { writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + if (item.Value == null) + { + writer.WriteNullValue(); + continue; + } +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif } writer.WriteEndObject(); } @@ -91,7 +103,7 @@ internal static InternalRunStepDeltaStepDetailsToolCallsFileSearchObject Deseria } int index = default; string id = default; - IReadOnlyDictionary fileSearch = default; + IReadOnlyDictionary fileSearch = default; string type = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -109,10 +121,17 @@ internal static InternalRunStepDeltaStepDetailsToolCallsFileSearchObject Deseria } if (property.NameEquals("file_search"u8)) { - Dictionary dictionary = new Dictionary(); + Dictionary dictionary = new Dictionary(); foreach (var property0 in property.Value.EnumerateObject()) { - dictionary.Add(property0.Name, property0.Value.GetString()); + if (property0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property0.Name, null); + } + else + { + dictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText())); + } } fileSearch = dictionary; continue; diff --git a/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.cs b/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.cs index 6fcfc013c..e3db470bb 100644 --- a/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.cs +++ b/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.cs @@ -9,7 +9,7 @@ namespace OpenAI.Assistants { internal partial class InternalRunStepDeltaStepDetailsToolCallsFileSearchObject : InternalRunStepDeltaStepDetailsToolCallsObjectToolCallsObject { - internal InternalRunStepDeltaStepDetailsToolCallsFileSearchObject(int index, IReadOnlyDictionary fileSearch) + internal InternalRunStepDeltaStepDetailsToolCallsFileSearchObject(int index, IReadOnlyDictionary fileSearch) { Argument.AssertNotNull(fileSearch, nameof(fileSearch)); @@ -18,7 +18,7 @@ internal InternalRunStepDeltaStepDetailsToolCallsFileSearchObject(int index, IRe FileSearch = fileSearch; } - internal InternalRunStepDeltaStepDetailsToolCallsFileSearchObject(string type, IDictionary serializedAdditionalRawData, int index, string id, IReadOnlyDictionary fileSearch) : base(type, serializedAdditionalRawData) + internal InternalRunStepDeltaStepDetailsToolCallsFileSearchObject(string type, IDictionary serializedAdditionalRawData, int index, string id, IReadOnlyDictionary fileSearch) : base(type, serializedAdditionalRawData) { Index = index; Id = id; @@ -31,6 +31,6 @@ internal InternalRunStepDeltaStepDetailsToolCallsFileSearchObject() public int Index { get; } public string Id { get; } - public IReadOnlyDictionary FileSearch { get; } + public IReadOnlyDictionary FileSearch { get; } } } diff --git a/src/Generated/Models/InternalRunStepFileSearchToolCallDetails.Serialization.cs b/src/Generated/Models/InternalRunStepFileSearchToolCallDetails.Serialization.cs index e89d929f4..34d26af6a 100644 --- a/src/Generated/Models/InternalRunStepFileSearchToolCallDetails.Serialization.cs +++ b/src/Generated/Models/InternalRunStepFileSearchToolCallDetails.Serialization.cs @@ -33,7 +33,19 @@ void IJsonModel.Write(Utf8JsonWriter w foreach (var item in FileSearch) { writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + if (item.Value == null) + { + writer.WriteNullValue(); + continue; + } +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif } writer.WriteEndObject(); } @@ -85,7 +97,7 @@ internal static InternalRunStepFileSearchToolCallDetails DeserializeInternalRunS return null; } string id = default; - IReadOnlyDictionary fileSearch = default; + IReadOnlyDictionary fileSearch = default; string type = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -98,10 +110,17 @@ internal static InternalRunStepFileSearchToolCallDetails DeserializeInternalRunS } if (property.NameEquals("file_search"u8)) { - Dictionary dictionary = new Dictionary(); + Dictionary dictionary = new Dictionary(); foreach (var property0 in property.Value.EnumerateObject()) { - dictionary.Add(property0.Name, property0.Value.GetString()); + if (property0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property0.Name, null); + } + else + { + dictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText())); + } } fileSearch = dictionary; continue; diff --git a/src/Generated/Models/InternalRunStepFileSearchToolCallDetails.cs b/src/Generated/Models/InternalRunStepFileSearchToolCallDetails.cs index 6be9fec00..f1593afd7 100644 --- a/src/Generated/Models/InternalRunStepFileSearchToolCallDetails.cs +++ b/src/Generated/Models/InternalRunStepFileSearchToolCallDetails.cs @@ -9,7 +9,7 @@ namespace OpenAI.Assistants { internal partial class InternalRunStepFileSearchToolCallDetails : RunStepToolCall { - internal InternalRunStepFileSearchToolCallDetails(string id, IReadOnlyDictionary fileSearch) + internal InternalRunStepFileSearchToolCallDetails(string id, IReadOnlyDictionary fileSearch) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(fileSearch, nameof(fileSearch)); @@ -19,7 +19,7 @@ internal InternalRunStepFileSearchToolCallDetails(string id, IReadOnlyDictionary FileSearch = fileSearch; } - internal InternalRunStepFileSearchToolCallDetails(string type, IDictionary serializedAdditionalRawData, string id, IReadOnlyDictionary fileSearch) : base(type, serializedAdditionalRawData) + internal InternalRunStepFileSearchToolCallDetails(string type, IDictionary serializedAdditionalRawData, string id, IReadOnlyDictionary fileSearch) : base(type, serializedAdditionalRawData) { Id = id; FileSearch = fileSearch; @@ -30,6 +30,6 @@ internal InternalRunStepFileSearchToolCallDetails() } public string Id { get; } - public IReadOnlyDictionary FileSearch { get; } + public IReadOnlyDictionary FileSearch { get; } } } diff --git a/src/Generated/Models/UnknownChatMessage.Serialization.cs b/src/Generated/Models/InternalUnknownChatMessage.Serialization.cs similarity index 56% rename from src/Generated/Models/UnknownChatMessage.Serialization.cs rename to src/Generated/Models/InternalUnknownChatMessage.Serialization.cs index 665911fca..4ff268505 100644 --- a/src/Generated/Models/UnknownChatMessage.Serialization.cs +++ b/src/Generated/Models/InternalUnknownChatMessage.Serialization.cs @@ -5,11 +5,12 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; namespace OpenAI.Chat { - internal partial class UnknownChatMessage : IJsonModel + internal partial class InternalUnknownChatMessage : IJsonModel { ChatMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { @@ -23,6 +24,40 @@ ChatMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReade return DeserializeChatMessage(document.RootElement, options); } + internal static InternalUnknownChatMessage DeserializeInternalUnknownChatMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ChatMessageRole role = default; + IList content = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("role"u8)) + { + role = property.Value.GetString().ToChatMessageRole(); + continue; + } + if (property.NameEquals("content"u8)) + { + DeserializeContentValue(property, ref content); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalUnknownChatMessage(role, content ?? new ChangeTrackingList(), serializedAdditionalRawData); + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; @@ -54,10 +89,10 @@ ChatMessage IPersistableModel.Create(BinaryData data, ModelReaderWr string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - internal static new UnknownChatMessage FromResponse(PipelineResponse response) + internal static new InternalUnknownChatMessage FromResponse(PipelineResponse response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeUnknownChatMessage(document.RootElement); + return DeserializeInternalUnknownChatMessage(document.RootElement); } internal override BinaryContent ToBinaryContent() diff --git a/src/Generated/Models/InternalUnknownChatMessage.cs b/src/Generated/Models/InternalUnknownChatMessage.cs new file mode 100644 index 000000000..8f25fa22a --- /dev/null +++ b/src/Generated/Models/InternalUnknownChatMessage.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Chat +{ + internal partial class InternalUnknownChatMessage : ChatMessage + { + internal InternalUnknownChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData) : base(role, content, serializedAdditionalRawData) + { + } + + internal InternalUnknownChatMessage() + { + } + } +} diff --git a/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs b/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs index 0bc64d31b..756d520b6 100644 --- a/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs +++ b/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs @@ -12,42 +12,6 @@ namespace OpenAI.Chat { internal partial class InternalUnknownChatResponseFormat : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(ChatResponseFormat)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("type") != true) - { - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - ChatResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; diff --git a/src/Generated/Models/SpeechGenerationOptions.Serialization.cs b/src/Generated/Models/SpeechGenerationOptions.Serialization.cs index 9b2c260b6..823b6165b 100644 --- a/src/Generated/Models/SpeechGenerationOptions.Serialization.cs +++ b/src/Generated/Models/SpeechGenerationOptions.Serialization.cs @@ -39,12 +39,12 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReade if (SerializedAdditionalRawData?.ContainsKey("response_format") != true && Optional.IsDefined(ResponseFormat)) { writer.WritePropertyName("response_format"u8); - writer.WriteStringValue(ResponseFormat.Value.ToSerialString()); + writer.WriteStringValue(ResponseFormat.Value.ToString()); } - if (SerializedAdditionalRawData?.ContainsKey("speed") != true && Optional.IsDefined(Speed)) + if (SerializedAdditionalRawData?.ContainsKey("speed") != true && Optional.IsDefined(SpeedRatio)) { writer.WritePropertyName("speed"u8); - writer.WriteNumberValue(Speed.Value); + writer.WriteNumberValue(SpeedRatio.Value); } if (SerializedAdditionalRawData != null) { @@ -118,7 +118,7 @@ internal static SpeechGenerationOptions DeserializeSpeechGenerationOptions(JsonE { continue; } - responseFormat = property.Value.GetString().ToGeneratedSpeechFormat(); + responseFormat = new GeneratedSpeechFormat(property.Value.GetString()); continue; } if (property.NameEquals("speed"u8)) diff --git a/src/Generated/Models/SpeechGenerationOptions.cs b/src/Generated/Models/SpeechGenerationOptions.cs index 4a5b48c18..8ecda5dc0 100644 --- a/src/Generated/Models/SpeechGenerationOptions.cs +++ b/src/Generated/Models/SpeechGenerationOptions.cs @@ -11,16 +11,15 @@ public partial class SpeechGenerationOptions { internal IDictionary SerializedAdditionalRawData { get; set; } - internal SpeechGenerationOptions(InternalCreateSpeechRequestModel model, string input, GeneratedSpeechVoice voice, GeneratedSpeechFormat? responseFormat, float? speed, IDictionary serializedAdditionalRawData) + internal SpeechGenerationOptions(InternalCreateSpeechRequestModel model, string input, GeneratedSpeechVoice voice, GeneratedSpeechFormat? responseFormat, float? speedRatio, IDictionary serializedAdditionalRawData) { Model = model; Input = input; Voice = voice; ResponseFormat = responseFormat; - Speed = speed; + SpeedRatio = speedRatio; SerializedAdditionalRawData = serializedAdditionalRawData; } public GeneratedSpeechFormat? ResponseFormat { get; set; } - public float? Speed { get; set; } } } diff --git a/src/Generated/Models/UnknownChatMessage.cs b/src/Generated/Models/UnknownChatMessage.cs deleted file mode 100644 index 431558af6..000000000 --- a/src/Generated/Models/UnknownChatMessage.cs +++ /dev/null @@ -1,20 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Chat -{ - internal partial class UnknownChatMessage : ChatMessage - { - internal UnknownChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData) : base(role, content, serializedAdditionalRawData) - { - } - - internal UnknownChatMessage() - { - } - } -} diff --git a/tests/Assistants/AssistantTests.cs b/tests/Assistants/AssistantTests.cs index 898c4299b..921d436a3 100644 --- a/tests/Assistants/AssistantTests.cs +++ b/tests/Assistants/AssistantTests.cs @@ -1,6 +1,5 @@ using NUnit.Framework; using OpenAI.Assistants; -using OpenAI.Chat; using OpenAI.Files; using OpenAI.VectorStores; using System; @@ -9,7 +8,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Numerics; using System.Threading; using System.Threading.Tasks; using static OpenAI.Tests.TestHelpers; @@ -679,6 +677,67 @@ This file describes the favorite foods of several people. Assert.That(hasCake, Is.True); } + [Test] + public async Task BasicFileSearchStreamingWorks() + { + const string fileContent = """ + The favorite food of several people: + - Summanus Ferdinand: tacos + - Tekakwitha Effie: pizza + - Filip Carola: cake + """; + + const string fileName = "favorite_foods.txt"; + + FileClient fileClient = GetTestClient(TestScenario.Files); + AssistantClient client = GetTestClient(TestScenario.Assistants); + + // First, upload a simple test file. + OpenAIFileInfo testFile = fileClient.UploadFile(BinaryData.FromString(fileContent), fileName, FileUploadPurpose.Assistants); + Validate(testFile); + + // Create an assistant, using the creation helper to make a new vector store. + AssistantCreationOptions assistantCreationOptions = new() + { + Tools = { new FileSearchToolDefinition() }, + ToolResources = new() + { + FileSearch = new() + { + NewVectorStores = { new VectorStoreCreationHelper([testFile.Id]) } + } + } + }; + Assistant assistant = client.CreateAssistant("gpt-4o-mini", assistantCreationOptions); + Validate(assistant); + + Assert.That(assistant.ToolResources?.FileSearch?.VectorStoreIds, Has.Count.EqualTo(1)); + string vectorStoreId = assistant.ToolResources.FileSearch.VectorStoreIds[0]; + _vectorStoreIdsToDelete.Add(vectorStoreId); + + // Create a thread. + ThreadCreationOptions threadCreationOptions = new() + { + InitialMessages = { "Using the files you have available, what's Filip's favorite food?" } + }; + AssistantThread thread = client.CreateThread(threadCreationOptions); + Validate(thread); + + // Create run and stream the results. + AsyncCollectionResult streamingResult = client.CreateRunStreamingAsync(thread.Id, assistant.Id); + string message = string.Empty; + + await foreach (StreamingUpdate update in streamingResult) + { + if (update is MessageContentUpdate contentUpdate) + { + message += $"{contentUpdate.Text}"; + } + } + + Assert.That(message, Does.Contain("cake")); + } + [Test] public async Task Pagination_CanEnumerateAssistants() { diff --git a/tests/Audio/TextToSpeechTests.cs b/tests/Audio/TextToSpeechTests.cs index cbbd748d1..e875c69b9 100644 --- a/tests/Audio/TextToSpeechTests.cs +++ b/tests/Audio/TextToSpeechTests.cs @@ -32,19 +32,31 @@ public async Task BasicTextToSpeechWorks() [Test] [TestCase(null)] - [TestCase(GeneratedSpeechFormat.Mp3)] - [TestCase(GeneratedSpeechFormat.Opus)] - [TestCase(GeneratedSpeechFormat.Aac)] - [TestCase(GeneratedSpeechFormat.Flac)] - [TestCase(GeneratedSpeechFormat.Wav)] - [TestCase(GeneratedSpeechFormat.Pcm)] - public async Task OutputFormatWorks(GeneratedSpeechFormat? responseFormat) + [TestCase("mp3")] + [TestCase("opus")] + [TestCase("aac")] + [TestCase("flac")] + [TestCase("wav")] + [TestCase("pcm")] + public async Task OutputFormatWorks(string responseFormat) { AudioClient client = GetTestClient(TestScenario.Audio_TTS); - SpeechGenerationOptions options = responseFormat == null - ? new() - : new() { ResponseFormat = responseFormat }; + SpeechGenerationOptions options = new(); + + if (!string.IsNullOrEmpty(responseFormat)) + { + options.ResponseFormat = responseFormat switch + { + "mp3" => GeneratedSpeechFormat.Mp3, + "opus" => GeneratedSpeechFormat.Opus, + "aac" => GeneratedSpeechFormat.Aac, + "flac" => GeneratedSpeechFormat.Flac, + "wav" => GeneratedSpeechFormat.Wav, + "pcm" => GeneratedSpeechFormat.Pcm, + _ => throw new ArgumentException("Invalid response format") + }; + } BinaryData audio = IsAsync ? await client.GenerateSpeechAsync("Hello, world!", GeneratedSpeechVoice.Alloy, options)