openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
mailinhphan/clientOptions

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

OpenAI/src/Generated/Models/Files/InternalAddUploadPartRequest.Serialization.cs

134lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.ClientModel.Primitives;
7using System.Collections.Generic;
8using System.Text.Json;
9using OpenAI;
10
11namespace OpenAI.Files
12{
13 internal partial class InternalAddUploadPartRequest : IJsonModel<InternalAddUploadPartRequest>
14 {
15 internal InternalAddUploadPartRequest()
16 {
17 }
18
19 protected virtual InternalAddUploadPartRequest PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
20 {
21 string format = options.Format == "W" ? ((IPersistableModel<InternalAddUploadPartRequest>)this).GetFormatFromOptions(options) : options.Format;
22 switch (format)
23 {
24 case "J":
25 using (JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions))
26 {
27 return DeserializeInternalAddUploadPartRequest(document.RootElement, options);
28 }
29 default:
30 throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support reading '{options.Format}' format.");
31 }
32 }
33
34 protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
35 {
36 string format = options.Format == "W" ? ((IPersistableModel<InternalAddUploadPartRequest>)this).GetFormatFromOptions(options) : options.Format;
37 switch (format)
38 {
39 case "J":
40 return ModelReaderWriter.Write(this, options, OpenAIContext.Default);
41 default:
42 throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support writing '{options.Format}' format.");
43 }
44 }
45
46 BinaryData IPersistableModel<InternalAddUploadPartRequest>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
47
48 InternalAddUploadPartRequest IPersistableModel<InternalAddUploadPartRequest>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
49
50 string IPersistableModel<InternalAddUploadPartRequest>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
51
52 void IJsonModel<InternalAddUploadPartRequest>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
53 {
54 writer.WriteStartObject();
55 JsonModelWriteCore(writer, options);
56 writer.WriteEndObject();
57 }
58
59 protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
60 {
61 string format = options.Format == "W" ? ((IPersistableModel<InternalAddUploadPartRequest>)this).GetFormatFromOptions(options) : options.Format;
62 if (format != "J")
63 {
64 throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support writing '{format}' format.");
65 }
66 if (_additionalBinaryDataProperties?.ContainsKey("data") != true)
67 {
68 writer.WritePropertyName("data"u8);
69#if NET6_0_OR_GREATER
70 writer.WriteRawValue(Data);
71#else
72 using (JsonDocument document = JsonDocument.Parse(Data))
73 {
74 JsonSerializer.Serialize(writer, document.RootElement);
75 }
76#endif
77 }
78 // Plugin customization: remove options.Format != "W" check
79 if (_additionalBinaryDataProperties != null)
80 {
81 foreach (var item in _additionalBinaryDataProperties)
82 {
83 if (ModelSerializationExtensions.IsSentinelValue(item.Value))
84 {
85 continue;
86 }
87 writer.WritePropertyName(item.Key);
88#if NET6_0_OR_GREATER
89 writer.WriteRawValue(item.Value);
90#else
91 using (JsonDocument document = JsonDocument.Parse(item.Value))
92 {
93 JsonSerializer.Serialize(writer, document.RootElement);
94 }
95#endif
96 }
97 }
98 }
99
100 InternalAddUploadPartRequest IJsonModel<InternalAddUploadPartRequest>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
101
102 protected virtual InternalAddUploadPartRequest JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
103 {
104 string format = options.Format == "W" ? ((IPersistableModel<InternalAddUploadPartRequest>)this).GetFormatFromOptions(options) : options.Format;
105 if (format != "J")
106 {
107 throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support reading '{format}' format.");
108 }
109 using JsonDocument document = JsonDocument.ParseValue(ref reader);
110 return DeserializeInternalAddUploadPartRequest(document.RootElement, options);
111 }
112
113 internal static InternalAddUploadPartRequest DeserializeInternalAddUploadPartRequest(JsonElement element, ModelReaderWriterOptions options)
114 {
115 if (element.ValueKind == JsonValueKind.Null)
116 {
117 return null;
118 }
119 BinaryData data = default;
120 IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
121 foreach (var prop in element.EnumerateObject())
122 {
123 if (prop.NameEquals("data"u8))
124 {
125 data = BinaryData.FromString(prop.Value.GetRawText());
126 continue;
127 }
128 // Plugin customization: remove options.Format != "W" check
129 additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
130 }
131 return new InternalAddUploadPartRequest(data, additionalBinaryDataProperties);
132 }
133 }
134}
135