openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
achandmsft-patch-2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Generated/Models/Assistants/AssistantResponseFormat.Serialization.cs

91lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.ClientModel.Primitives;
7using System.Text.Json;
8using OpenAI;
9
10namespace OpenAI.Assistants
11{
12 [PersistableModelProxy(typeof(InternalUnknownDotNetAssistantResponseFormat))]
13 public partial class AssistantResponseFormat : IJsonModel<AssistantResponseFormat>
14 {
15 internal AssistantResponseFormat()
16 {
17 }
18
19 protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
20 {
21 string format = options.Format == "W" ? ((IPersistableModel<AssistantResponseFormat>)this).GetFormatFromOptions(options) : options.Format;
22 if (format != "J")
23 {
24 throw new FormatException($"The model {nameof(AssistantResponseFormat)} does not support writing '{format}' format.");
25 }
26 if (_additionalBinaryDataProperties?.ContainsKey("type") != true)
27 {
28 writer.WritePropertyName("type"u8);
29 writer.WriteStringValue(Kind.ToString());
30 }
31 // Plugin customization: remove options.Format != "W" check
32 if (_additionalBinaryDataProperties != null)
33 {
34 foreach (var item in _additionalBinaryDataProperties)
35 {
36 if (ModelSerializationExtensions.IsSentinelValue(item.Value))
37 {
38 continue;
39 }
40 writer.WritePropertyName(item.Key);
41#if NET6_0_OR_GREATER
42 writer.WriteRawValue(item.Value);
43#else
44 using (JsonDocument document = JsonDocument.Parse(item.Value))
45 {
46 JsonSerializer.Serialize(writer, document.RootElement);
47 }
48#endif
49 }
50 }
51 }
52
53 protected virtual AssistantResponseFormat JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
54 {
55 string format = options.Format == "W" ? ((IPersistableModel<AssistantResponseFormat>)this).GetFormatFromOptions(options) : options.Format;
56 if (format != "J")
57 {
58 throw new FormatException($"The model {nameof(AssistantResponseFormat)} does not support reading '{format}' format.");
59 }
60 using JsonDocument document = JsonDocument.ParseValue(ref reader);
61 return DeserializeAssistantResponseFormat(document.RootElement, options);
62 }
63
64 protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
65 {
66 string format = options.Format == "W" ? ((IPersistableModel<AssistantResponseFormat>)this).GetFormatFromOptions(options) : options.Format;
67 switch (format)
68 {
69 case "J":
70 return ModelReaderWriter.Write(this, options, OpenAIContext.Default);
71 default:
72 throw new FormatException($"The model {nameof(AssistantResponseFormat)} does not support writing '{options.Format}' format.");
73 }
74 }
75
76 protected virtual AssistantResponseFormat PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
77 {
78 string format = options.Format == "W" ? ((IPersistableModel<AssistantResponseFormat>)this).GetFormatFromOptions(options) : options.Format;
79 switch (format)
80 {
81 case "J":
82 using (JsonDocument document = JsonDocument.Parse(data))
83 {
84 return DeserializeAssistantResponseFormat(document.RootElement, options);
85 }
86 default:
87 throw new FormatException($"The model {nameof(AssistantResponseFormat)} does not support reading '{options.Format}' format.");
88 }
89 }
90 }
91}
92