|
| 1 | +// <auto-generated/> |
| 2 | + |
| 3 | +#nullable disable |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.ClientModel.Primitives; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Diagnostics.CodeAnalysis; |
| 9 | +using System.Text.Json; |
| 10 | +using OpenAI; |
| 11 | + |
| 12 | +namespace OpenAI.Responses |
| 13 | +{ |
| 14 | + public partial class StreamingResponseTextAnnotationAddedUpdate : IJsonModel<StreamingResponseTextAnnotationAddedUpdate> |
| 15 | + { |
| 16 | + internal StreamingResponseTextAnnotationAddedUpdate() : this(InternalResponseStreamEventType.ResponseOutputTextAnnotationAdded, default, null, null, default, default, default, null) |
| 17 | + { |
| 18 | + } |
| 19 | + |
| 20 | + void IJsonModel<StreamingResponseTextAnnotationAddedUpdate>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 21 | + { |
| 22 | + writer.WriteStartObject(); |
| 23 | + JsonModelWriteCore(writer, options); |
| 24 | + writer.WriteEndObject(); |
| 25 | + } |
| 26 | + |
| 27 | + [Experimental("OPENAI001")] |
| 28 | + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) |
| 29 | + { |
| 30 | + string format = options.Format == "W" ? ((IPersistableModel<StreamingResponseTextAnnotationAddedUpdate>)this).GetFormatFromOptions(options) : options.Format; |
| 31 | + if (format != "J") |
| 32 | + { |
| 33 | + throw new FormatException($"The model {nameof(StreamingResponseTextAnnotationAddedUpdate)} does not support writing '{format}' format."); |
| 34 | + } |
| 35 | + base.JsonModelWriteCore(writer, options); |
| 36 | + if (_additionalBinaryDataProperties?.ContainsKey("item_id") != true) |
| 37 | + { |
| 38 | + writer.WritePropertyName("item_id"u8); |
| 39 | + writer.WriteStringValue(ItemId); |
| 40 | + } |
| 41 | + if (_additionalBinaryDataProperties?.ContainsKey("output_index") != true) |
| 42 | + { |
| 43 | + writer.WritePropertyName("output_index"u8); |
| 44 | + writer.WriteNumberValue(OutputIndex); |
| 45 | + } |
| 46 | + if (_additionalBinaryDataProperties?.ContainsKey("content_index") != true) |
| 47 | + { |
| 48 | + writer.WritePropertyName("content_index"u8); |
| 49 | + writer.WriteNumberValue(ContentIndex); |
| 50 | + } |
| 51 | + if (_additionalBinaryDataProperties?.ContainsKey("annotation_index") != true) |
| 52 | + { |
| 53 | + writer.WritePropertyName("annotation_index"u8); |
| 54 | + writer.WriteNumberValue(AnnotationIndex); |
| 55 | + } |
| 56 | + if (_additionalBinaryDataProperties?.ContainsKey("annotation") != true) |
| 57 | + { |
| 58 | + writer.WritePropertyName("annotation"u8); |
| 59 | +#if NET6_0_OR_GREATER |
| 60 | + writer.WriteRawValue(Annotation); |
| 61 | +#else |
| 62 | + using (JsonDocument document = JsonDocument.Parse(Annotation)) |
| 63 | + { |
| 64 | + JsonSerializer.Serialize(writer, document.RootElement); |
| 65 | + } |
| 66 | +#endif |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + StreamingResponseTextAnnotationAddedUpdate IJsonModel<StreamingResponseTextAnnotationAddedUpdate>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (StreamingResponseTextAnnotationAddedUpdate)JsonModelCreateCore(ref reader, options); |
| 71 | + |
| 72 | + [Experimental("OPENAI001")] |
| 73 | + protected override StreamingResponseUpdate JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) |
| 74 | + { |
| 75 | + string format = options.Format == "W" ? ((IPersistableModel<StreamingResponseTextAnnotationAddedUpdate>)this).GetFormatFromOptions(options) : options.Format; |
| 76 | + if (format != "J") |
| 77 | + { |
| 78 | + throw new FormatException($"The model {nameof(StreamingResponseTextAnnotationAddedUpdate)} does not support reading '{format}' format."); |
| 79 | + } |
| 80 | + using JsonDocument document = JsonDocument.ParseValue(ref reader); |
| 81 | + return DeserializeStreamingResponseTextAnnotationAddedUpdate(document.RootElement, options); |
| 82 | + } |
| 83 | + |
| 84 | + internal static StreamingResponseTextAnnotationAddedUpdate DeserializeStreamingResponseTextAnnotationAddedUpdate(JsonElement element, ModelReaderWriterOptions options) |
| 85 | + { |
| 86 | + if (element.ValueKind == JsonValueKind.Null) |
| 87 | + { |
| 88 | + return null; |
| 89 | + } |
| 90 | + InternalResponseStreamEventType kind = default; |
| 91 | + int sequenceNumber = default; |
| 92 | + IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>(); |
| 93 | + string itemId = default; |
| 94 | + int outputIndex = default; |
| 95 | + int contentIndex = default; |
| 96 | + int annotationIndex = default; |
| 97 | + BinaryData annotation = default; |
| 98 | + foreach (var prop in element.EnumerateObject()) |
| 99 | + { |
| 100 | + if (prop.NameEquals("type"u8)) |
| 101 | + { |
| 102 | + kind = new InternalResponseStreamEventType(prop.Value.GetString()); |
| 103 | + continue; |
| 104 | + } |
| 105 | + if (prop.NameEquals("sequence_number"u8)) |
| 106 | + { |
| 107 | + sequenceNumber = prop.Value.GetInt32(); |
| 108 | + continue; |
| 109 | + } |
| 110 | + if (prop.NameEquals("item_id"u8)) |
| 111 | + { |
| 112 | + itemId = prop.Value.GetString(); |
| 113 | + continue; |
| 114 | + } |
| 115 | + if (prop.NameEquals("output_index"u8)) |
| 116 | + { |
| 117 | + outputIndex = prop.Value.GetInt32(); |
| 118 | + continue; |
| 119 | + } |
| 120 | + if (prop.NameEquals("content_index"u8)) |
| 121 | + { |
| 122 | + contentIndex = prop.Value.GetInt32(); |
| 123 | + continue; |
| 124 | + } |
| 125 | + if (prop.NameEquals("annotation_index"u8)) |
| 126 | + { |
| 127 | + annotationIndex = prop.Value.GetInt32(); |
| 128 | + continue; |
| 129 | + } |
| 130 | + if (prop.NameEquals("annotation"u8)) |
| 131 | + { |
| 132 | + annotation = BinaryData.FromString(prop.Value.GetRawText()); |
| 133 | + continue; |
| 134 | + } |
| 135 | + // Plugin customization: remove options.Format != "W" check |
| 136 | + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); |
| 137 | + } |
| 138 | + return new StreamingResponseTextAnnotationAddedUpdate( |
| 139 | + kind, |
| 140 | + sequenceNumber, |
| 141 | + additionalBinaryDataProperties, |
| 142 | + itemId, |
| 143 | + outputIndex, |
| 144 | + contentIndex, |
| 145 | + annotationIndex, |
| 146 | + annotation); |
| 147 | + } |
| 148 | + |
| 149 | + BinaryData IPersistableModel<StreamingResponseTextAnnotationAddedUpdate>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); |
| 150 | + |
| 151 | + [Experimental("OPENAI001")] |
| 152 | + protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) |
| 153 | + { |
| 154 | + string format = options.Format == "W" ? ((IPersistableModel<StreamingResponseTextAnnotationAddedUpdate>)this).GetFormatFromOptions(options) : options.Format; |
| 155 | + switch (format) |
| 156 | + { |
| 157 | + case "J": |
| 158 | + return ModelReaderWriter.Write(this, options, OpenAIContext.Default); |
| 159 | + default: |
| 160 | + throw new FormatException($"The model {nameof(StreamingResponseTextAnnotationAddedUpdate)} does not support writing '{options.Format}' format."); |
| 161 | + } |
| 162 | + } |
| 163 | + |
| 164 | + StreamingResponseTextAnnotationAddedUpdate IPersistableModel<StreamingResponseTextAnnotationAddedUpdate>.Create(BinaryData data, ModelReaderWriterOptions options) => (StreamingResponseTextAnnotationAddedUpdate)PersistableModelCreateCore(data, options); |
| 165 | + |
| 166 | + [Experimental("OPENAI001")] |
| 167 | + protected override StreamingResponseUpdate PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) |
| 168 | + { |
| 169 | + string format = options.Format == "W" ? ((IPersistableModel<StreamingResponseTextAnnotationAddedUpdate>)this).GetFormatFromOptions(options) : options.Format; |
| 170 | + switch (format) |
| 171 | + { |
| 172 | + case "J": |
| 173 | + using (JsonDocument document = JsonDocument.Parse(data)) |
| 174 | + { |
| 175 | + return DeserializeStreamingResponseTextAnnotationAddedUpdate(document.RootElement, options); |
| 176 | + } |
| 177 | + default: |
| 178 | + throw new FormatException($"The model {nameof(StreamingResponseTextAnnotationAddedUpdate)} does not support reading '{options.Format}' format."); |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + string IPersistableModel<StreamingResponseTextAnnotationAddedUpdate>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; |
| 183 | + } |
| 184 | +} |
0 commit comments