openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/modify-responsesclient-default-model

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Custom/Assistants/AssistantResponseFormat.Serialization.cs

61lines · modecode

1using Microsoft.TypeSpec.Generator.Customizations;
2using System;
3using System.ClientModel;
4using System.ClientModel.Primitives;
5using System.Text.Json;
6
7namespace OpenAI.Assistants;
8
9[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel<OpenAI.Assistants.AssistantResponseFormat>.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))]
10[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel<OpenAI.Assistants.AssistantResponseFormat>.Create", typeof(Utf8JsonReader), typeof(ModelReaderWriterOptions))]
11[CodeGenSuppress("global::System.ClientModel.Primitives.IPersistableModel<OpenAI.Assistants.AssistantResponseFormat>.Write", typeof(ModelReaderWriterOptions))]
12[CodeGenSuppress("global::System.ClientModel.Primitives.IPersistableModel<OpenAI.Assistants.AssistantResponseFormat>.Create", typeof(BinaryData), typeof(ModelReaderWriterOptions))]
13[CodeGenSuppress("global::System.ClientModel.Primitives.IPersistableModel<OpenAI.Assistants.AssistantResponseFormat>.GetFormatFromOptions", typeof(ModelReaderWriterOptions))]
14public partial class AssistantResponseFormat : IJsonModel<AssistantResponseFormat>
15{
16 internal static void SerializeAssistantResponseFormat(AssistantResponseFormat instance, Utf8JsonWriter writer, ModelReaderWriterOptions options = null)
17 {
18 throw new InvalidOperationException();
19 }
20
21 internal static AssistantResponseFormat DeserializeAssistantResponseFormat(JsonElement element, ModelReaderWriterOptions options = null)
22 {
23 return element.ValueKind switch
24 {
25 JsonValueKind.String => InternalAssistantResponseFormatPlainTextNoObject.DeserializeInternalAssistantResponseFormatPlainTextNoObject(element, options),
26 JsonValueKind.Object when element.TryGetProperty("type", out JsonElement discriminatorElement)
27 => discriminatorElement.GetString() switch
28 {
29 "json_object" => InternalDotNetAssistantResponseFormatJsonObject.DeserializeInternalDotNetAssistantResponseFormatJsonObject(element, options),
30 "json_schema" => InternalDotNetAssistantResponseFormatJsonSchema.DeserializeInternalDotNetAssistantResponseFormatJsonSchema(element, options),
31 "text" => InternalDotNetAssistantResponseFormatText.DeserializeInternalDotNetAssistantResponseFormatText(element, options),
32 _ => InternalUnknownDotNetAssistantResponseFormat.DeserializeInternalUnknownDotNetAssistantResponseFormat(element, options),
33 },
34 _ => null,
35 };
36 }
37
38 void IJsonModel<AssistantResponseFormat>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
39 => CustomSerializationHelpers.SerializeInstance(this, SerializeAssistantResponseFormat, writer, options);
40
41 AssistantResponseFormat IJsonModel<AssistantResponseFormat>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
42 => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeAssistantResponseFormat, ref reader, options);
43
44 BinaryData IPersistableModel<AssistantResponseFormat>.Write(ModelReaderWriterOptions options)
45 => CustomSerializationHelpers.SerializeInstance(this, options);
46
47 AssistantResponseFormat IPersistableModel<AssistantResponseFormat>.Create(BinaryData data, ModelReaderWriterOptions options)
48 => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeAssistantResponseFormat, data, options);
49
50 string IPersistableModel<AssistantResponseFormat>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
51
52 internal static AssistantResponseFormat FromResponse(PipelineResponse response)
53 {
54 throw new InvalidOperationException();
55 }
56
57 internal virtual BinaryContent ToBinaryContent()
58 {
59 return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions);
60 }
61}
62