openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Generated/Models/AssistantModificationOptions.Serialization.cs
358lines · 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 AssistantModificationOptions : IJsonModel<AssistantModificationOptions> | |
| 14 | { | |
| 15 | void IJsonModel<AssistantModificationOptions>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) | |
| 16 | { | |
| 17 | var format = options.Format == "W" ? ((IPersistableModel<AssistantModificationOptions>)this).GetFormatFromOptions(options) : options.Format; | |
| 18 | if (format != "J") | |
| 19 | { | |
| 20 | throw new FormatException($"The model {nameof(AssistantModificationOptions)} does not support writing '{format}' format."); | |
| 21 | } | |
| 22 | | |
| 23 | writer.WriteStartObject(); | |
| 24 | if (Optional.IsDefined(Model)) | |
| 25 | { | |
| 26 | writer.WritePropertyName("model"u8); | |
| 27 | writer.WriteStringValue(Model); | |
| 28 | } | |
| 29 | if (Optional.IsDefined(Name)) | |
| 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 | } | |
| 41 | if (Optional.IsDefined(Description)) | |
| 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 | } | |
| 53 | if (Optional.IsDefined(Instructions)) | |
| 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 | } | |
| 65 | if (Optional.IsCollectionDefined(DefaultTools)) | |
| 66 | { | |
| 67 | writer.WritePropertyName("tools"u8); | |
| 68 | writer.WriteStartArray(); | |
| 69 | foreach (var item in DefaultTools) | |
| 70 | { | |
| 71 | writer.WriteObjectValue<ToolDefinition>(item, options); | |
| 72 | } | |
| 73 | writer.WriteEndArray(); | |
| 74 | } | |
| 75 | if (Optional.IsDefined(ToolResources)) | |
| 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 | } | |
| 87 | if (Optional.IsCollectionDefined(Metadata)) | |
| 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 | } | |
| 105 | if (Optional.IsDefined(Temperature)) | |
| 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 | } | |
| 117 | if (Optional.IsDefined(NucleusSamplingFactor)) | |
| 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 | } | |
| 129 | if (Optional.IsDefined(ResponseFormat)) | |
| 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 | } | |
| 141 | if (true && _serializedAdditionalRawData != null) | |
| 142 | { | |
| 143 | foreach (var item in _serializedAdditionalRawData) | |
| 144 | { | |
| 145 | writer.WritePropertyName(item.Key); | |
| 146 | #if NET6_0_OR_GREATER | |
| 147 | writer.WriteRawValue(item.Value); | |
| 148 | #else | |
| 149 | using (JsonDocument document = JsonDocument.Parse(item.Value)) | |
| 150 | { | |
| 151 | JsonSerializer.Serialize(writer, document.RootElement); | |
| 152 | } | |
| 153 | #endif | |
| 154 | } | |
| 155 | } | |
| 156 | writer.WriteEndObject(); | |
| 157 | } | |
| 158 | | |
| 159 | AssistantModificationOptions IJsonModel<AssistantModificationOptions>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) | |
| 160 | { | |
| 161 | var format = options.Format == "W" ? ((IPersistableModel<AssistantModificationOptions>)this).GetFormatFromOptions(options) : options.Format; | |
| 162 | if (format != "J") | |
| 163 | { | |
| 164 | throw new FormatException($"The model {nameof(AssistantModificationOptions)} does not support reading '{format}' format."); | |
| 165 | } | |
| 166 | | |
| 167 | using JsonDocument document = JsonDocument.ParseValue(ref reader); | |
| 168 | return DeserializeAssistantModificationOptions(document.RootElement, options); | |
| 169 | } | |
| 170 | | |
| 171 | internal static AssistantModificationOptions DeserializeAssistantModificationOptions(JsonElement element, ModelReaderWriterOptions options = null) | |
| 172 | { | |
| 173 | options ??= ModelSerializationExtensions.WireOptions; | |
| 174 | | |
| 175 | if (element.ValueKind == JsonValueKind.Null) | |
| 176 | { | |
| 177 | return null; | |
| 178 | } | |
| 179 | string model = default; | |
| 180 | string name = default; | |
| 181 | string description = default; | |
| 182 | string instructions = default; | |
| 183 | IList<ToolDefinition> tools = default; | |
| 184 | ToolResources toolResources = default; | |
| 185 | IDictionary<string, string> metadata = default; | |
| 186 | float? temperature = default; | |
| 187 | float? topP = default; | |
| 188 | AssistantResponseFormat responseFormat = default; | |
| 189 | IDictionary<string, BinaryData> serializedAdditionalRawData = default; | |
| 190 | Dictionary<string, BinaryData> rawDataDictionary = new Dictionary<string, BinaryData>(); | |
| 191 | foreach (var property in element.EnumerateObject()) | |
| 192 | { | |
| 193 | if (property.NameEquals("model"u8)) | |
| 194 | { | |
| 195 | model = property.Value.GetString(); | |
| 196 | continue; | |
| 197 | } | |
| 198 | if (property.NameEquals("name"u8)) | |
| 199 | { | |
| 200 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 201 | { | |
| 202 | name = null; | |
| 203 | continue; | |
| 204 | } | |
| 205 | name = property.Value.GetString(); | |
| 206 | continue; | |
| 207 | } | |
| 208 | if (property.NameEquals("description"u8)) | |
| 209 | { | |
| 210 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 211 | { | |
| 212 | description = null; | |
| 213 | continue; | |
| 214 | } | |
| 215 | description = property.Value.GetString(); | |
| 216 | continue; | |
| 217 | } | |
| 218 | if (property.NameEquals("instructions"u8)) | |
| 219 | { | |
| 220 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 221 | { | |
| 222 | instructions = null; | |
| 223 | continue; | |
| 224 | } | |
| 225 | instructions = property.Value.GetString(); | |
| 226 | continue; | |
| 227 | } | |
| 228 | if (property.NameEquals("tools"u8)) | |
| 229 | { | |
| 230 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 231 | { | |
| 232 | continue; | |
| 233 | } | |
| 234 | List<ToolDefinition> array = new List<ToolDefinition>(); | |
| 235 | foreach (var item in property.Value.EnumerateArray()) | |
| 236 | { | |
| 237 | array.Add(ToolDefinition.DeserializeToolDefinition(item, options)); | |
| 238 | } | |
| 239 | tools = array; | |
| 240 | continue; | |
| 241 | } | |
| 242 | if (property.NameEquals("tool_resources"u8)) | |
| 243 | { | |
| 244 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 245 | { | |
| 246 | toolResources = null; | |
| 247 | continue; | |
| 248 | } | |
| 249 | toolResources = Assistants.ToolResources.DeserializeToolResources(property.Value, options); | |
| 250 | continue; | |
| 251 | } | |
| 252 | if (property.NameEquals("metadata"u8)) | |
| 253 | { | |
| 254 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 255 | { | |
| 256 | continue; | |
| 257 | } | |
| 258 | Dictionary<string, string> dictionary = new Dictionary<string, string>(); | |
| 259 | foreach (var property0 in property.Value.EnumerateObject()) | |
| 260 | { | |
| 261 | dictionary.Add(property0.Name, property0.Value.GetString()); | |
| 262 | } | |
| 263 | metadata = dictionary; | |
| 264 | continue; | |
| 265 | } | |
| 266 | if (property.NameEquals("temperature"u8)) | |
| 267 | { | |
| 268 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 269 | { | |
| 270 | temperature = null; | |
| 271 | continue; | |
| 272 | } | |
| 273 | temperature = property.Value.GetSingle(); | |
| 274 | continue; | |
| 275 | } | |
| 276 | if (property.NameEquals("top_p"u8)) | |
| 277 | { | |
| 278 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 279 | { | |
| 280 | topP = null; | |
| 281 | continue; | |
| 282 | } | |
| 283 | topP = property.Value.GetSingle(); | |
| 284 | continue; | |
| 285 | } | |
| 286 | if (property.NameEquals("response_format"u8)) | |
| 287 | { | |
| 288 | if (property.Value.ValueKind == JsonValueKind.Null) | |
| 289 | { | |
| 290 | responseFormat = null; | |
| 291 | continue; | |
| 292 | } | |
| 293 | responseFormat = AssistantResponseFormat.DeserializeAssistantResponseFormat(property.Value, options); | |
| 294 | continue; | |
| 295 | } | |
| 296 | if (true) | |
| 297 | { | |
| 298 | rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); | |
| 299 | } | |
| 300 | } | |
| 301 | serializedAdditionalRawData = rawDataDictionary; | |
| 302 | return new AssistantModificationOptions( | |
| 303 | model, | |
| 304 | name, | |
| 305 | description, | |
| 306 | instructions, | |
| 307 | tools ?? new ChangeTrackingList<ToolDefinition>(), | |
| 308 | toolResources, | |
| 309 | metadata ?? new ChangeTrackingDictionary<string, string>(), | |
| 310 | temperature, | |
| 311 | topP, | |
| 312 | responseFormat, | |
| 313 | serializedAdditionalRawData); | |
| 314 | } | |
| 315 | | |
| 316 | BinaryData IPersistableModel<AssistantModificationOptions>.Write(ModelReaderWriterOptions options) | |
| 317 | { | |
| 318 | var format = options.Format == "W" ? ((IPersistableModel<AssistantModificationOptions>)this).GetFormatFromOptions(options) : options.Format; | |
| 319 | | |
| 320 | switch (format) | |
| 321 | { | |
| 322 | case "J": | |
| 323 | return ModelReaderWriter.Write(this, options); | |
| 324 | default: | |
| 325 | throw new FormatException($"The model {nameof(AssistantModificationOptions)} does not support writing '{options.Format}' format."); | |
| 326 | } | |
| 327 | } | |
| 328 | | |
| 329 | AssistantModificationOptions IPersistableModel<AssistantModificationOptions>.Create(BinaryData data, ModelReaderWriterOptions options) | |
| 330 | { | |
| 331 | var format = options.Format == "W" ? ((IPersistableModel<AssistantModificationOptions>)this).GetFormatFromOptions(options) : options.Format; | |
| 332 | | |
| 333 | switch (format) | |
| 334 | { | |
| 335 | case "J": | |
| 336 | { | |
| 337 | using JsonDocument document = JsonDocument.Parse(data); | |
| 338 | return DeserializeAssistantModificationOptions(document.RootElement, options); | |
| 339 | } | |
| 340 | default: | |
| 341 | throw new FormatException($"The model {nameof(AssistantModificationOptions)} does not support reading '{options.Format}' format."); | |
| 342 | } | |
| 343 | } | |
| 344 | | |
| 345 | string IPersistableModel<AssistantModificationOptions>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; | |
| 346 | | |
| 347 | internal static AssistantModificationOptions FromResponse(PipelineResponse response) | |
| 348 | { | |
| 349 | using var document = JsonDocument.Parse(response.Content); | |
| 350 | return DeserializeAssistantModificationOptions(document.RootElement); | |
| 351 | } | |
| 352 | | |
| 353 | internal virtual BinaryContent ToBinaryContent() | |
| 354 | { | |
| 355 | return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); | |
| 356 | } | |
| 357 | } | |
| 358 | } |