11using System ;
2+ using System . ClientModel ;
23using System . ClientModel . Primitives ;
3- using System . Collections . Generic ;
44using System . Text . Json ;
55
66namespace OpenAI . Assistants ;
@@ -9,10 +9,33 @@ namespace OpenAI.Assistants;
99[ CodeGenSuppress ( "global::System.ClientModel.Primitives.IJsonModel<OpenAI.Assistants.AssistantResponseFormat>.Create" , typeof ( Utf8JsonReader ) , typeof ( ModelReaderWriterOptions ) ) ]
1010[ CodeGenSuppress ( "global::System.ClientModel.Primitives.IPersistableModel<OpenAI.Assistants.AssistantResponseFormat>.Write" , typeof ( ModelReaderWriterOptions ) ) ]
1111[ CodeGenSuppress ( "global::System.ClientModel.Primitives.IPersistableModel<OpenAI.Assistants.AssistantResponseFormat>.Create" , typeof ( BinaryData ) , typeof ( ModelReaderWriterOptions ) ) ]
12+ [ CodeGenSuppress ( "global::System.ClientModel.Primitives.IPersistableModel<OpenAI.Assistants.AssistantResponseFormat>.GetFormatFromOptions" , typeof ( ModelReaderWriterOptions ) ) ]
1213public partial class AssistantResponseFormat : IJsonModel < AssistantResponseFormat >
1314{
15+ internal static void SerializeAssistantResponseFormat ( AssistantResponseFormat instance , Utf8JsonWriter writer , ModelReaderWriterOptions options = null )
16+ {
17+ throw new InvalidOperationException ( ) ;
18+ }
19+
20+ internal static AssistantResponseFormat DeserializeAssistantResponseFormat ( JsonElement element , ModelReaderWriterOptions options = null )
21+ {
22+ return element . ValueKind switch
23+ {
24+ JsonValueKind . String => InternalAssistantResponseFormatPlainTextNoObject . DeserializeInternalAssistantResponseFormatPlainTextNoObject ( element , options ) ,
25+ JsonValueKind . Object when element . TryGetProperty ( "type" , out JsonElement discriminatorElement )
26+ => discriminatorElement . GetString ( ) switch
27+ {
28+ "json_object" => InternalAssistantResponseFormatJsonObject . DeserializeInternalAssistantResponseFormatJsonObject ( element , options ) ,
29+ "json_schema" => InternalAssistantResponseFormatJsonSchema . DeserializeInternalAssistantResponseFormatJsonSchema ( element , options ) ,
30+ "text" => InternalAssistantResponseFormatText . DeserializeInternalAssistantResponseFormatText ( element , options ) ,
31+ _ => null ,
32+ } ,
33+ _ => null ,
34+ } ;
35+ }
36+
1437 void IJsonModel < AssistantResponseFormat > . Write ( Utf8JsonWriter writer , ModelReaderWriterOptions options )
15- => CustomSerializationHelpers . SerializeInstance ( this , SerializeAssistantResponseFormat , writer , options ) ;
38+ => CustomSerializationHelpers . SerializeInstance ( this , SerializeAssistantResponseFormat , writer , options ) ;
1639
1740 AssistantResponseFormat IJsonModel < AssistantResponseFormat > . Create ( ref Utf8JsonReader reader , ModelReaderWriterOptions options )
1841 => CustomSerializationHelpers . DeserializeNewInstance ( this , DeserializeAssistantResponseFormat , ref reader , options ) ;
@@ -23,53 +46,15 @@ BinaryData IPersistableModel<AssistantResponseFormat>.Write(ModelReaderWriterOpt
2346 AssistantResponseFormat IPersistableModel < AssistantResponseFormat > . Create ( BinaryData data , ModelReaderWriterOptions options )
2447 => CustomSerializationHelpers . DeserializeNewInstance ( this , DeserializeAssistantResponseFormat , data , options ) ;
2548
26- internal static void SerializeAssistantResponseFormat ( AssistantResponseFormat formatInstance , Utf8JsonWriter writer , ModelReaderWriterOptions options )
49+ string IPersistableModel < AssistantResponseFormat > . GetFormatFromOptions ( ModelReaderWriterOptions options ) => "J" ;
50+
51+ internal static AssistantResponseFormat FromResponse ( PipelineResponse response )
2752 {
28- if ( formatInstance . _plainTextValue is not null )
29- {
30- writer . WriteStringValue ( formatInstance . _plainTextValue ) ;
31- }
32- else
33- {
34- writer . WriteStartObject ( ) ;
35- writer . WritePropertyName ( "type"u8 ) ;
36- writer . WriteStringValue ( formatInstance . _objectType ) ;
37- writer . WriteSerializedAdditionalRawData ( formatInstance . SerializedAdditionalRawData , options ) ;
38- writer . WriteEndObject ( ) ;
39- }
53+ throw new InvalidOperationException ( ) ;
4054 }
4155
42- internal static AssistantResponseFormat DeserializeAssistantResponseFormat ( JsonElement element , ModelReaderWriterOptions options = null )
56+ internal virtual BinaryContent ToBinaryContent ( )
4357 {
44- options ??= ModelSerializationExtensions . WireOptions ;
45-
46- string plainTextValue = null ;
47- string objectType = null ;
48- IDictionary < string , BinaryData > rawDataDictionary = new ChangeTrackingDictionary < string , BinaryData > ( ) ;
49-
50- if ( element . ValueKind == JsonValueKind . Null )
51- {
52- return null ;
53- }
54- else if ( element . ValueKind == JsonValueKind . String )
55- {
56- plainTextValue = element . GetString ( ) ;
57- }
58- else
59- {
60- foreach ( var property in element . EnumerateObject ( ) )
61- {
62- if ( property . NameEquals ( "type"u8 ) )
63- {
64- objectType = property . Value . GetString ( ) ;
65- continue ;
66- }
67- if ( true )
68- {
69- rawDataDictionary . Add ( property . Name , BinaryData . FromString ( property . Value . GetRawText ( ) ) ) ;
70- }
71- }
72- }
73- return new AssistantResponseFormat ( plainTextValue , objectType , rawDataDictionary ) ;
58+ return BinaryContent . Create ( this , ModelSerializationExtensions . WireOptions ) ;
7459 }
7560}
0 commit comments