openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Generated/Internal/BinaryContentHelper.cs

119lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.ClientModel;
7using System.Collections.Generic;
8using System.Text.Json;
9
10namespace OpenAI
11{
12 internal static class BinaryContentHelper
13 {
14 public static BinaryContent FromEnumerable<T>(IEnumerable<T> enumerable)
15 where T : notnull
16 {
17 Utf8JsonBinaryContent content = new Utf8JsonBinaryContent();
18 content.JsonWriter.WriteStartArray();
19 foreach (var item in enumerable)
20 {
21 content.JsonWriter.WriteObjectValue(item, ModelSerializationExtensions.WireOptions);
22 }
23 content.JsonWriter.WriteEndArray();
24
25 return content;
26 }
27
28 public static BinaryContent FromEnumerable(IEnumerable<BinaryData> enumerable)
29 {
30 Utf8JsonBinaryContent content = new Utf8JsonBinaryContent();
31 content.JsonWriter.WriteStartArray();
32 foreach (var item in enumerable)
33 {
34 if (item == null)
35 {
36 content.JsonWriter.WriteNullValue();
37 }
38 else
39 {
40#if NET6_0_OR_GREATER
41 content.JsonWriter.WriteRawValue(item);
42#else
43 using (JsonDocument document = JsonDocument.Parse(item))
44 {
45 JsonSerializer.Serialize(content.JsonWriter, document.RootElement);
46 }
47#endif
48 }
49 }
50 content.JsonWriter.WriteEndArray();
51
52 return content;
53 }
54
55 public static BinaryContent FromDictionary<TValue>(IDictionary<string, TValue> dictionary)
56 where TValue : notnull
57 {
58 Utf8JsonBinaryContent content = new Utf8JsonBinaryContent();
59 content.JsonWriter.WriteStartObject();
60 foreach (var item in dictionary)
61 {
62 content.JsonWriter.WritePropertyName(item.Key);
63 content.JsonWriter.WriteObjectValue(item.Value, ModelSerializationExtensions.WireOptions);
64 }
65 content.JsonWriter.WriteEndObject();
66
67 return content;
68 }
69
70 public static BinaryContent FromDictionary(IDictionary<string, BinaryData> dictionary)
71 {
72 Utf8JsonBinaryContent content = new Utf8JsonBinaryContent();
73 content.JsonWriter.WriteStartObject();
74 foreach (var item in dictionary)
75 {
76 content.JsonWriter.WritePropertyName(item.Key);
77 if (item.Value == null)
78 {
79 content.JsonWriter.WriteNullValue();
80 }
81 else
82 {
83#if NET6_0_OR_GREATER
84 content.JsonWriter.WriteRawValue(item.Value);
85#else
86 using (JsonDocument document = JsonDocument.Parse(item.Value))
87 {
88 JsonSerializer.Serialize(content.JsonWriter, document.RootElement);
89 }
90#endif
91 }
92 }
93 content.JsonWriter.WriteEndObject();
94
95 return content;
96 }
97
98 public static BinaryContent FromObject(object value)
99 {
100 Utf8JsonBinaryContent content = new Utf8JsonBinaryContent();
101 content.JsonWriter.WriteObjectValue<object>(value, ModelSerializationExtensions.WireOptions);
102 return content;
103 }
104
105 public static BinaryContent FromObject(BinaryData value)
106 {
107 Utf8JsonBinaryContent content = new Utf8JsonBinaryContent();
108#if NET6_0_OR_GREATER
109 content.JsonWriter.WriteRawValue(value);
110#else
111 using (JsonDocument document = JsonDocument.Parse(value))
112 {
113 JsonSerializer.Serialize(content.JsonWriter, document.RootElement);
114 }
115#endif
116 return content;
117 }
118 }
119}
120