diff --git a/.dotnet/CHANGELOG.md b/.dotnet/CHANGELOG.md index d94e4c1be..692161c3c 100644 --- a/.dotnet/CHANGELOG.md +++ b/.dotnet/CHANGELOG.md @@ -18,6 +18,7 @@ ### 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 diff --git a/.dotnet/api/OpenAI.netstandard2.0.cs b/.dotnet/api/OpenAI.netstandard2.0.cs index b21008e0c..26140d4b9 100644 --- a/.dotnet/api/OpenAI.netstandard2.0.cs +++ b/.dotnet/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(); @@ -1215,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(); @@ -1347,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; } @@ -1415,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; } @@ -1522,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; @@ -1601,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); @@ -1613,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); @@ -1625,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/.dotnet/src/Custom/Assistants/CodeInterpreterToolDefinition.Serialization.cs b/.dotnet/src/Custom/Assistants/CodeInterpreterToolDefinition.Serialization.cs index eae645a69..8c89a3ff8 100644 --- a/.dotnet/src/Custom/Assistants/CodeInterpreterToolDefinition.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Assistants/FileSearchToolDefinition.Serialization.cs b/.dotnet/src/Custom/Assistants/FileSearchToolDefinition.Serialization.cs index 36968d793..6e4f9a8a4 100644 --- a/.dotnet/src/Custom/Assistants/FileSearchToolDefinition.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Assistants/FunctionToolDefinition.Serialization.cs b/.dotnet/src/Custom/Assistants/FunctionToolDefinition.Serialization.cs index 37506d837..81638da72 100644 --- a/.dotnet/src/Custom/Assistants/FunctionToolDefinition.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Assistants/Internal/UnknownAssistantToolDefinition.Serialization.cs b/.dotnet/src/Custom/Assistants/Internal/UnknownAssistantToolDefinition.Serialization.cs index b990dcbad..59524b086 100644 --- a/.dotnet/src/Custom/Assistants/Internal/UnknownAssistantToolDefinition.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Assistants/ToolDefinition.Serialization.cs b/.dotnet/src/Custom/Assistants/ToolDefinition.Serialization.cs index 629e0f53b..3f69a6a7c 100644 --- a/.dotnet/src/Custom/Assistants/ToolDefinition.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/AssistantChatMessage.Serialization.cs b/.dotnet/src/Custom/Chat/AssistantChatMessage.Serialization.cs index 44749c211..53faea0bb 100644 --- a/.dotnet/src/Custom/Chat/AssistantChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/ChatMessage.Serialization.cs b/.dotnet/src/Custom/Chat/ChatMessage.Serialization.cs index 007212010..39ea1f59d 100644 --- a/.dotnet/src/Custom/Chat/ChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/ChatResponseFormat.Serialization.cs b/.dotnet/src/Custom/Chat/ChatResponseFormat.Serialization.cs new file mode 100644 index 000000000..80372fd43 --- /dev/null +++ b/.dotnet/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/.dotnet/src/Custom/Chat/ChatResponseFormat.cs b/.dotnet/src/Custom/Chat/ChatResponseFormat.cs index 2b7feb1b8..cf4e5d783 100644 --- a/.dotnet/src/Custom/Chat/ChatResponseFormat.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/FunctionChatMessage.Serialization.cs b/.dotnet/src/Custom/Chat/FunctionChatMessage.Serialization.cs index 0bf7c4b18..b63581413 100644 --- a/.dotnet/src/Custom/Chat/FunctionChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/GeneratorStubs.cs b/.dotnet/src/Custom/Chat/Internal/GeneratorStubs.cs index f52ceaa79..87294c512 100644 --- a/.dotnet/src/Custom/Chat/Internal/GeneratorStubs.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.Serialization.cs b/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.Serialization.cs new file mode 100644 index 000000000..0e6b09480 --- /dev/null +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.cs b/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatJsonObject.cs new file mode 100644 index 000000000..f161ae7a8 --- /dev/null +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.Serialization.cs b/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.Serialization.cs new file mode 100644 index 000000000..ee171b4d7 --- /dev/null +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.cs b/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.cs new file mode 100644 index 000000000..cd9e63b5a --- /dev/null +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatText.Serialization.cs b/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatText.Serialization.cs new file mode 100644 index 000000000..30f5fe5ee --- /dev/null +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatText.cs b/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatText.cs new file mode 100644 index 000000000..3df5a8bf5 --- /dev/null +++ b/.dotnet/src/Custom/Chat/Internal/InternalChatResponseFormatText.cs @@ -0,0 +1,6 @@ +namespace OpenAI.Chat; + +[CodeGenModel("ChatResponseFormatText")] +internal partial class InternalChatResponseFormatText +{ +} diff --git a/.dotnet/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs b/.dotnet/src/Custom/Chat/Internal/InternalUnknownChatMessage.Serialization.cs similarity index 77% rename from .dotnet/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs rename to .dotnet/src/Custom/Chat/Internal/InternalUnknownChatMessage.Serialization.cs index aa3efbb42..a9575f0d1 100644 --- a/.dotnet/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/UnknownChatMessage.cs b/.dotnet/src/Custom/Chat/Internal/InternalUnknownChatMessage.cs similarity index 56% rename from .dotnet/src/Custom/Chat/Internal/UnknownChatMessage.cs rename to .dotnet/src/Custom/Chat/Internal/InternalUnknownChatMessage.cs index ac4faf00f..cb046b82e 100644 --- a/.dotnet/src/Custom/Chat/Internal/UnknownChatMessage.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.Serialization.cs b/.dotnet/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.Serialization.cs new file mode 100644 index 000000000..f64b69738 --- /dev/null +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.cs b/.dotnet/src/Custom/Chat/Internal/InternalUnknownChatResponseFormat.cs new file mode 100644 index 000000000..b869078fc --- /dev/null +++ b/.dotnet/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/.dotnet/src/Custom/Chat/Internal/AsyncStreamingChatCompletionUpdateCollection.cs b/.dotnet/src/Custom/Chat/Internal/Streaming/AsyncStreamingChatCompletionUpdateCollection.cs similarity index 100% rename from .dotnet/src/Custom/Chat/Internal/AsyncStreamingChatCompletionUpdateCollection.cs rename to .dotnet/src/Custom/Chat/Internal/Streaming/AsyncStreamingChatCompletionUpdateCollection.cs diff --git a/.dotnet/src/Custom/Chat/Internal/StreamingChatCompletionUpdateCollection.cs b/.dotnet/src/Custom/Chat/Internal/Streaming/StreamingChatCompletionUpdateCollection.cs similarity index 100% rename from .dotnet/src/Custom/Chat/Internal/StreamingChatCompletionUpdateCollection.cs rename to .dotnet/src/Custom/Chat/Internal/Streaming/StreamingChatCompletionUpdateCollection.cs diff --git a/.dotnet/src/Custom/Chat/SystemChatMessage.Serialization.cs b/.dotnet/src/Custom/Chat/SystemChatMessage.Serialization.cs index b1063b03f..3e02bd8e3 100644 --- a/.dotnet/src/Custom/Chat/SystemChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/ToolChatMessage.Serialization.cs b/.dotnet/src/Custom/Chat/ToolChatMessage.Serialization.cs index 9eb64d17e..6c4edc3b5 100644 --- a/.dotnet/src/Custom/Chat/ToolChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Chat/UserChatMessage.Serialization.cs b/.dotnet/src/Custom/Chat/UserChatMessage.Serialization.cs index fcd98a834..dd8c689f1 100644 --- a/.dotnet/src/Custom/Chat/UserChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Custom/Common/Internal/GeneratorStubs.cs b/.dotnet/src/Custom/Common/Internal/GeneratorStubs.cs index d0c7de7f2..a6172b6ac 100644 --- a/.dotnet/src/Custom/Common/Internal/GeneratorStubs.cs +++ b/.dotnet/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/.dotnet/src/Custom/Common/Internal/InternalResponseFormatJsonSchemaJsonSchema.cs b/.dotnet/src/Custom/Common/Internal/InternalResponseFormatJsonSchemaJsonSchema.cs new file mode 100644 index 000000000..7fa1d70fd --- /dev/null +++ b/.dotnet/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/.dotnet/src/Generated/Models/ChatMessage.Serialization.cs b/.dotnet/src/Generated/Models/ChatMessage.Serialization.cs index 3d13375d1..971105a95 100644 --- a/.dotnet/src/Generated/Models/ChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Generated/Models/ChatResponseFormat.Serialization.cs b/.dotnet/src/Generated/Models/ChatResponseFormat.Serialization.cs index 2c055865b..26c297851 100644 --- a/.dotnet/src/Generated/Models/ChatResponseFormat.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs b/.dotnet/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs index 9c63f887b..3e555b657 100644 --- a/.dotnet/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs b/.dotnet/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs index c5c0cca64..c2b875ee6 100644 --- a/.dotnet/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs b/.dotnet/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs index c0f373c9d..6ab2655f8 100644 --- a/.dotnet/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Generated/Models/UnknownChatMessage.Serialization.cs b/.dotnet/src/Generated/Models/InternalUnknownChatMessage.Serialization.cs similarity index 56% rename from .dotnet/src/Generated/Models/UnknownChatMessage.Serialization.cs rename to .dotnet/src/Generated/Models/InternalUnknownChatMessage.Serialization.cs index 665911fca..4ff268505 100644 --- a/.dotnet/src/Generated/Models/UnknownChatMessage.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Generated/Models/InternalUnknownChatMessage.cs b/.dotnet/src/Generated/Models/InternalUnknownChatMessage.cs new file mode 100644 index 000000000..8f25fa22a --- /dev/null +++ b/.dotnet/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/.dotnet/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs b/.dotnet/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs index 0bc64d31b..756d520b6 100644 --- a/.dotnet/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs +++ b/.dotnet/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/.dotnet/src/Generated/Models/UnknownChatMessage.cs b/.dotnet/src/Generated/Models/UnknownChatMessage.cs deleted file mode 100644 index 431558af6..000000000 --- a/.dotnet/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() - { - } - } -}