openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.12

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Chat/Internal/InternalChatResponseFormatJsonSchema.Serialization.cs

49lines · modecode

1using System.ClientModel.Primitives;
2using System.Text.Json;
3
4namespace OpenAI.Chat;
5
6[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel<OpenAI.Chat.InternalChatResponseFormatJsonSchema>.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))]
7internal partial class InternalChatResponseFormatJsonSchema : IJsonModel<InternalChatResponseFormatJsonSchema>
8{
9 void IJsonModel<InternalChatResponseFormatJsonSchema>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
10 => CustomSerializationHelpers.SerializeInstance(this, SerializeInternalChatResponseFormatJsonSchema, writer, options);
11
12 internal static void SerializeInternalChatResponseFormatJsonSchema(InternalChatResponseFormatJsonSchema instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
13 => instance.WriteCore(writer, options);
14
15 internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
16 {
17 writer.WriteStartObject();
18 if (SerializedAdditionalRawData?.ContainsKey("json_schema") != true)
19 {
20 writer.WritePropertyName("json_schema"u8);
21 writer.WriteObjectValue(JsonSchema, options);
22 }
23 if (SerializedAdditionalRawData?.ContainsKey("type") != true)
24 {
25 writer.WritePropertyName("type"u8);
26 writer.WriteStringValue(Type);
27 }
28 if (SerializedAdditionalRawData != null)
29 {
30 foreach (var item in SerializedAdditionalRawData)
31 {
32 if (ModelSerializationExtensions.IsSentinelValue(item.Value))
33 {
34 continue;
35 }
36 writer.WritePropertyName(item.Key);
37#if NET6_0_OR_GREATER
38 writer.WriteRawValue(item.Value);
39#else
40 using (JsonDocument document = JsonDocument.Parse(item.Value))
41 {
42 JsonSerializer.Serialize(writer, document.RootElement);
43 }
44#endif
45 }
46 }
47 writer.WriteEndObject();
48 }
49}
50