openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Generated/Models/AssistantCreationOptions.Serialization.cs
363lines · modeblame
9f9f2936Jose Arriaga Maldonado2 years ago | 1 | // <auto-generated/> |
| 2 | | |
| 3 | #nullable disable | |
| 4 | | |
| 5 | using System; | |
| 6 | using System.ClientModel; | |
| 7 | using System.ClientModel.Primitives; | |
| 8 | using System.Collections.Generic; | |
| 9 | using System.Text.Json; | |
| 10 | | |
| 11 | namespace OpenAI.Assistants | |
| 12 | { | |
| 13 | public partial class AssistantCreationOptions : IJsonModel<AssistantCreationOptions> | |
| 14 | { | |
| 15 | void IJsonModel<AssistantCreationOptions>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) | |
| 16 | { | |
| 17 | var format = options.Format == "W" ? ((IPersistableModel<AssistantCreationOptions>)this).GetFormatFromOptions(options) : options.Format; | |
| 18 | if (format != "J") | |
| 19 | { | |
| 20 | throw new FormatException($"The model {nameof(AssistantCreationOptions)} does not support writing '{format}' format."); | |
| 21 | } | |
| 22 | | |
| 23 | writer.WriteStartObject(); | |
19fc7d54Jose Arriaga Maldonado2 years ago | 24 | if (SerializedAdditionalRawData?.ContainsKey("model") != true) |
| 25 | { | |
| 26 | writer.WritePropertyName("model"u8); | |
| 27 | writer.WriteStringValue(Model); | |
| 28 | } | |
| 29 | if (SerializedAdditionalRawData?.ContainsKey("name") != true && Optional.IsDefined(Name)) | |
9f9f2936Jose Arriaga Maldonado2 years ago | 30 | { |
| 31 | if (Name != null) | |
| 32 | { | |
| 33 | writer.WritePropertyName("name"u8); | |
| 34 | writer.WriteStringValue(Name); | |
| 35 | } | |
| 36 | else | |
| 37 | { | |
| 38 | writer.WriteNull("name"); | |
| 39 | } | |
| 40 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 41 | if (SerializedAdditionalRawData?.ContainsKey("description") != true && Optional.IsDefined(Description)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 42 | { |
| 43 | if (Description != null) | |
| 44 | { | |
| 45 | writer.WritePropertyName("description"u8); | |
| 46 | writer.WriteStringValue(Description); | |
| 47 | } | |
| 48 | else | |
| 49 | { | |
| 50 | writer.WriteNull("description"); | |
| 51 | } | |
| 52 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 53 | if (SerializedAdditionalRawData?.ContainsKey("instructions") != true && Optional.IsDefined(Instructions)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 54 | { |
| 55 | if (Instructions != null) | |
| 56 | { | |
| 57 | writer.WritePropertyName("instructions"u8); | |
| 58 | writer.WriteStringValue(Instructions); | |
| 59 | } | |
| 60 | else | |
| 61 | { | |
| 62 | writer.WriteNull("instructions"); | |
| 63 | } | |
| 64 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 65 | if (SerializedAdditionalRawData?.ContainsKey("tools") != true && Optional.IsCollectionDefined(Tools)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 66 | { |
| 67 | writer.WritePropertyName("tools"u8); | |
| 68 | writer.WriteStartArray(); | |
| 69 | foreach (var item in Tools) | |
| 70 | { | |
| 71 | writer.WriteObjectValue<ToolDefinition>(item, options); | |
| 72 | } | |
| 73 | writer.WriteEndArray(); | |
| 74 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 75 | if (SerializedAdditionalRawData?.ContainsKey("tool_resources") != true && Optional.IsDefined(ToolResources)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 76 | { |
| 77 | if (ToolResources != null) | |
| 78 | { | |
| 79 | writer.WritePropertyName("tool_resources"u8); | |
| 80 | writer.WriteObjectValue<ToolResources>(ToolResources, options); | |
| 81 | } | |
| 82 | else | |
| 83 | { | |
| 84 | writer.WriteNull("tool_resources"); | |
| 85 | } | |
| 86 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 87 | if (SerializedAdditionalRawData?.ContainsKey("metadata") != true && Optional.IsCollectionDefined(Metadata)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 88 | { |
| 89 | if (Metadata != null) | |
| 90 | { | |
| 91 | writer.WritePropertyName("metadata"u8); | |
| 92 | writer.WriteStartObject(); | |
| 93 | foreach (var item in Metadata) | |
| 94 | { | |
| 95 | writer.WritePropertyName(item.Key); | |
| 96 | writer.WriteStringValue(item.Value); | |
| 97 | } | |
| 98 | writer.WriteEndObject(); | |
| 99 | } | |
| 100 | else | |
| 101 | { | |
| 102 | writer.WriteNull("metadata"); | |
| 103 | } | |
| 104 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 105 | if (SerializedAdditionalRawData?.ContainsKey("temperature") != true && Optional.IsDefined(Temperature)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 106 | { |
| 107 | if (Temperature != null) | |
| 108 | { | |
| 109 | writer.WritePropertyName("temperature"u8); | |
| 110 | writer.WriteNumberValue(Temperature.Value); | |
| 111 | } | |
| 112 | else | |
| 113 | { | |
| 114 | writer.WriteNull("temperature"); | |
| 115 | } | |
| 116 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 117 | if (SerializedAdditionalRawData?.ContainsKey("top_p") != true && Optional.IsDefined(NucleusSamplingFactor)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 118 | { |
| 119 | if (NucleusSamplingFactor != null) | |
| 120 | { | |
| 121 | writer.WritePropertyName("top_p"u8); | |
| 122 | writer.WriteNumberValue(NucleusSamplingFactor.Value); | |
| 123 | } | |
| 124 | else | |
| 125 | { | |
| 126 | writer.WriteNull("top_p"); | |
| 127 | } | |
| 128 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 129 | if (SerializedAdditionalRawData?.ContainsKey("response_format") != true && Optional.IsDefined(ResponseFormat)) |
9f9f2936Jose Arriaga Maldonado2 years ago | 130 | { |
| 131 | if (ResponseFormat != null) | |
| 132 | { | |
| 133 | writer.WritePropertyName("response_format"u8); | |
| 134 | writer.WriteObjectValue<AssistantResponseFormat>(ResponseFormat, options); | |
| 135 | } | |
| 136 | else | |
| 137 | { | |
| 138 | writer.WriteNull("response_format"); | |
| 139 | } | |
| 140 | } | |
19fc7d54Jose Arriaga Maldonado2 years ago | 141 | if (SerializedAdditionalRawData != null) |
9f9f2936Jose Arriaga Maldonado2 years ago | 142 | { |
19fc7d54Jose Arriaga Maldonado2 years ago | 143 | foreach (var item in SerializedAdditionalRawData) |
9f9f2936Jose Arriaga Maldonado2 years ago | 144 | { |
19fc7d54Jose Arriaga Maldonado2 years ago | 145 | if (ModelSerializationExtensions.IsSentinelValue(item.Value)) |
| 146 | { | |
| 147 | continue; | |
| 148 | } | |
9f9f2936Jose Arriaga Maldonado2 years ago | 149 | writer.WritePropertyName(item.Key); |
| 150 | #if NET6_0_OR_GREATER | |
| 151 | writer.WriteRawValue(item.Value); | |
| 152 | #else | |
| 153 | using (JsonDocument document = JsonDocument.Parse(item.Value)) | |
| 154 | { | |
| 155 | JsonSerializer.Serialize(writer, document.RootElement); | |
| 156 | } | |
| 157 | #endif | |
| 158 | } | |
| 159 | } | |
| 160 | writer.WriteEndObject(); | |
| 161 | } | |
| 162 | | |
| 163 | AssistantCreationOptions IJsonModel<AssistantCreationOptions>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) | |
| 164 | { | |
| 165 | var format = options.Format == "W" ? ((IPersistableModel<AssistantCreationOptions>)this).GetFormatFromOptions(options) : options.Format; | |
| 166 | if (format != "J") | |
| 167 | { | |
| 168 | throw new FormatException($"The model {nameof(AssistantCreationOptions)} does not support reading '{format}' format."); | |
| 169 | } | |
| 170 | | |
| 171 | using JsonDocument document = JsonDocument.ParseValue(ref reader); | |
| 172 | return DeserializeAssistantCreationOptions(document.RootElement, options); | |
| 173 | } | |
| 174 | | |
| 175 | internal static AssistantCreationOptions DeserializeAssistantCreationOptions(JsonElement element, ModelReaderWriterOptions options = null) | |
| 176 | { | |
| 177 | options ??= ModelSerializationExtensions.WireOptions; | |
| 178 | | |
| 179 | if (element.ValueKind == JsonValueKind.Null) | |
| 180 | { | |
| 181 | return null; | |
| 182 | } | |
| 183 | string model = default; | |
| 184 | string name = default; | |
| 185 | string description = default; | |
| 186 | string instructions = default; | |
| 187 | IList<ToolDefinition> tools = default; | |
| 188 | ToolResources toolResources = default; | |
| 189 | IDictionary<string, string> metadata = default; | |
| 190 | float? temperature = default; | |
| 191 | float? topP = default; | |
| 192 | AssistantResponseFormat responseFormat = default; | |
| 193 | IDictionary<string, BinaryData> serializedAdditionalRawData = default; | |
| 194 | Dictionary<string, BinaryData> rawDataDictionary = new Dictionary<string, BinaryData>(); | |
| 195 | foreach (var property in element.EnumerateObject()) | |
| 196 | { | |
| 197 | if (property.NameEquals("model"u8)) | |
| 198 | { | |
| 199 | model = property.Value.GetString(); | |
| 200 | continue; | |
| 201 | } | |
| 202 | if (property.NameEquals("name"u8)) | |
| 203 | { | |
| 204 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 205 | { | |
| 206 | name = null; | |
| 207 | continue; | |
| 208 | } | |
| 209 | name = property.Value.GetString(); | |
| 210 | continue; | |
| 211 | } | |
| 212 | if (property.NameEquals("description"u8)) | |
| 213 | { | |
| 214 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 215 | { | |
| 216 | description = null; | |
| 217 | continue; | |
| 218 | } | |
| 219 | description = property.Value.GetString(); | |
| 220 | continue; | |
| 221 | } | |
| 222 | if (property.NameEquals("instructions"u8)) | |
| 223 | { | |
| 224 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 225 | { | |
| 226 | instructions = null; | |
| 227 | continue; | |
| 228 | } | |
| 229 | instructions = property.Value.GetString(); | |
| 230 | continue; | |
| 231 | } | |
| 232 | if (property.NameEquals("tools"u8)) | |
| 233 | { | |
| 234 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 235 | { | |
| 236 | continue; | |
| 237 | } | |
| 238 | List<ToolDefinition> array = new List<ToolDefinition>(); | |
| 239 | foreach (var item in property.Value.EnumerateArray()) | |
| 240 | { | |
| 241 | array.Add(ToolDefinition.DeserializeToolDefinition(item, options)); | |
| 242 | } | |
| 243 | tools = array; | |
| 244 | continue; | |
| 245 | } | |
| 246 | if (property.NameEquals("tool_resources"u8)) | |
| 247 | { | |
| 248 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 249 | { | |
| 250 | toolResources = null; | |
| 251 | continue; | |
| 252 | } | |
| 253 | toolResources = Assistants.ToolResources.DeserializeToolResources(property.Value, options); | |
| 254 | continue; | |
| 255 | } | |
| 256 | if (property.NameEquals("metadata"u8)) | |
| 257 | { | |
| 258 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 259 | { | |
| 260 | continue; | |
| 261 | } | |
| 262 | Dictionary<string, string> dictionary = new Dictionary<string, string>(); | |
| 263 | foreach (var property0 in property.Value.EnumerateObject()) | |
| 264 | { | |
| 265 | dictionary.Add(property0.Name, property0.Value.GetString()); | |
| 266 | } | |
| 267 | metadata = dictionary; | |
| 268 | continue; | |
| 269 | } | |
| 270 | if (property.NameEquals("temperature"u8)) | |
| 271 | { | |
| 272 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 273 | { | |
| 274 | temperature = null; | |
| 275 | continue; | |
| 276 | } | |
| 277 | temperature = property.Value.GetSingle(); | |
| 278 | continue; | |
| 279 | } | |
| 280 | if (property.NameEquals("top_p"u8)) | |
| 281 | { | |
| 282 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 283 | { | |
| 284 | topP = null; | |
| 285 | continue; | |
| 286 | } | |
| 287 | topP = property.Value.GetSingle(); | |
| 288 | continue; | |
| 289 | } | |
| 290 | if (property.NameEquals("response_format"u8)) | |
| 291 | { | |
| 292 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 293 | { | |
| 294 | responseFormat = null; | |
| 295 | continue; | |
| 296 | } | |
| 297 | responseFormat = AssistantResponseFormat.DeserializeAssistantResponseFormat(property.Value, options); | |
| 298 | continue; | |
| 299 | } | |
32bfd2b6Jose Arriaga Maldonado2 years ago | 300 | if (true) |
9f9f2936Jose Arriaga Maldonado2 years ago | 301 | { |
19fc7d54Jose Arriaga Maldonado2 years ago | 302 | rawDataDictionary ??= new Dictionary<string, BinaryData>(); |
9f9f2936Jose Arriaga Maldonado2 years ago | 303 | rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); |
| 304 | } | |
| 305 | } | |
| 306 | serializedAdditionalRawData = rawDataDictionary; | |
| 307 | return new AssistantCreationOptions( | |
| 308 | model, | |
| 309 | name, | |
| 310 | description, | |
| 311 | instructions, | |
| 312 | tools ?? new ChangeTrackingList<ToolDefinition>(), | |
| 313 | toolResources, | |
| 314 | metadata ?? new ChangeTrackingDictionary<string, string>(), | |
| 315 | temperature, | |
| 316 | topP, | |
| 317 | responseFormat, | |
| 318 | serializedAdditionalRawData); | |
| 319 | } | |
| 320 | | |
| 321 | BinaryData IPersistableModel<AssistantCreationOptions>.Write(ModelReaderWriterOptions options) | |
| 322 | { | |
| 323 | var format = options.Format == "W" ? ((IPersistableModel<AssistantCreationOptions>)this).GetFormatFromOptions(options) : options.Format; | |
| 324 | | |
| 325 | switch (format) | |
| 326 | { | |
| 327 | case "J": | |
| 328 | return ModelReaderWriter.Write(this, options); | |
| 329 | default: | |
| 330 | throw new FormatException($"The model {nameof(AssistantCreationOptions)} does not support writing '{options.Format}' format."); | |
| 331 | } | |
| 332 | } | |
| 333 | | |
| 334 | AssistantCreationOptions IPersistableModel<AssistantCreationOptions>.Create(BinaryData data, ModelReaderWriterOptions options) | |
| 335 | { | |
| 336 | var format = options.Format == "W" ? ((IPersistableModel<AssistantCreationOptions>)this).GetFormatFromOptions(options) : options.Format; | |
| 337 | | |
| 338 | switch (format) | |
| 339 | { | |
| 340 | case "J": | |
| 341 | { | |
| 342 | using JsonDocument document = JsonDocument.Parse(data); | |
| 343 | return DeserializeAssistantCreationOptions(document.RootElement, options); | |
| 344 | } | |
| 345 | default: | |
| 346 | throw new FormatException($"The model {nameof(AssistantCreationOptions)} does not support reading '{options.Format}' format."); | |
| 347 | } | |
| 348 | } | |
| 349 | | |
| 350 | string IPersistableModel<AssistantCreationOptions>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; | |
| 351 | | |
| 352 | internal static AssistantCreationOptions FromResponse(PipelineResponse response) | |
| 353 | { | |
| 354 | using var document = JsonDocument.Parse(response.Content); | |
| 355 | return DeserializeAssistantCreationOptions(document.RootElement); | |
| 356 | } | |
| 357 | | |
| 358 | internal virtual BinaryContent ToBinaryContent() | |
| 359 | { | |
| 360 | return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); | |
| 361 | } | |
| 362 | } | |
| 363 | } |