openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.0.0-beta.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Generated/Models/AssistantChatMessage.Serialization.cs

68lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.ClientModel;
7using System.ClientModel.Primitives;
8using System.Text.Json;
9
10namespace OpenAI.Chat
11{
12 public partial class AssistantChatMessage : IJsonModel<AssistantChatMessage>
13 {
14 AssistantChatMessage IJsonModel<AssistantChatMessage>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
15 {
16 var format = options.Format == "W" ? ((IPersistableModel<AssistantChatMessage>)this).GetFormatFromOptions(options) : options.Format;
17 if (format != "J")
18 {
19 throw new FormatException($"The model {nameof(AssistantChatMessage)} does not support reading '{format}' format.");
20 }
21
22 using JsonDocument document = JsonDocument.ParseValue(ref reader);
23 return DeserializeAssistantChatMessage(document.RootElement, options);
24 }
25
26 BinaryData IPersistableModel<AssistantChatMessage>.Write(ModelReaderWriterOptions options)
27 {
28 var format = options.Format == "W" ? ((IPersistableModel<AssistantChatMessage>)this).GetFormatFromOptions(options) : options.Format;
29
30 switch (format)
31 {
32 case "J":
33 return ModelReaderWriter.Write(this, options);
34 default:
35 throw new FormatException($"The model {nameof(AssistantChatMessage)} does not support writing '{options.Format}' format.");
36 }
37 }
38
39 AssistantChatMessage IPersistableModel<AssistantChatMessage>.Create(BinaryData data, ModelReaderWriterOptions options)
40 {
41 var format = options.Format == "W" ? ((IPersistableModel<AssistantChatMessage>)this).GetFormatFromOptions(options) : options.Format;
42
43 switch (format)
44 {
45 case "J":
46 {
47 using JsonDocument document = JsonDocument.Parse(data);
48 return DeserializeAssistantChatMessage(document.RootElement, options);
49 }
50 default:
51 throw new FormatException($"The model {nameof(AssistantChatMessage)} does not support reading '{options.Format}' format.");
52 }
53 }
54
55 string IPersistableModel<AssistantChatMessage>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
56
57 internal static new AssistantChatMessage FromResponse(PipelineResponse response)
58 {
59 using var document = JsonDocument.Parse(response.Content);
60 return DeserializeAssistantChatMessage(document.RootElement);
61 }
62
63 internal override BinaryContent ToBinaryContent()
64 {
65 return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions);
66 }
67 }
68}
69