1+ #nullable enable
2+ #pragma warning disable CS0618 // Type or member is obsolete
3+
4+ namespace tryAGI . OpenAI . JsonConverters
5+ {
6+ /// <inheritdoc />
7+ public class OutputMessageContentJsonConverter : global ::System . Text . Json . Serialization . JsonConverter < global ::tryAGI . OpenAI . OutputMessageContent >
8+ {
9+ /// <inheritdoc />
10+ public override global ::tryAGI . OpenAI . OutputMessageContent Read (
11+ ref global ::System . Text . Json . Utf8JsonReader reader ,
12+ global ::System . Type typeToConvert ,
13+ global ::System . Text . Json . JsonSerializerOptions options )
14+ {
15+ options = options ?? throw new global ::System . ArgumentNullException ( nameof ( options ) ) ;
16+ var typeInfoResolver = options . TypeInfoResolver ?? throw new global ::System . InvalidOperationException ( "TypeInfoResolver is not set." ) ;
17+
18+ var
19+ readerCopy = reader ;
20+ global ::tryAGI . OpenAI . OutputTextContent ? text = default ;
21+ try
22+ {
23+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . OutputTextContent ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . OutputTextContent > ??
24+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . OutputTextContent ) . Name } ") ;
25+ text = global ::System . Text . Json . JsonSerializer . Deserialize ( ref readerCopy , typeInfo ) ;
26+ }
27+ catch ( global ::System . Text . Json . JsonException )
28+ {
29+ }
30+
31+ readerCopy = reader ;
32+ global ::tryAGI . OpenAI . RefusalContent ? refusal = default ;
33+ try
34+ {
35+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RefusalContent ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RefusalContent > ??
36+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RefusalContent ) . Name } ") ;
37+ refusal = global ::System . Text . Json . JsonSerializer . Deserialize ( ref readerCopy , typeInfo ) ;
38+ }
39+ catch ( global ::System . Text . Json . JsonException )
40+ {
41+ }
42+
43+ var result = new global ::tryAGI . OpenAI . OutputMessageContent (
44+ text ,
45+ refusal
46+ ) ;
47+
48+ if ( text != null )
49+ {
50+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . OutputTextContent ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . OutputTextContent > ??
51+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . OutputTextContent ) . Name } ") ;
52+ _ = global ::System . Text . Json . JsonSerializer . Deserialize ( ref reader , typeInfo ) ;
53+ }
54+ else if ( refusal != null )
55+ {
56+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RefusalContent ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RefusalContent > ??
57+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RefusalContent ) . Name } ") ;
58+ _ = global ::System . Text . Json . JsonSerializer . Deserialize ( ref reader , typeInfo ) ;
59+ }
60+
61+ return result ;
62+ }
63+
64+ /// <inheritdoc />
65+ public override void Write (
66+ global ::System . Text . Json . Utf8JsonWriter writer ,
67+ global ::tryAGI . OpenAI . OutputMessageContent value ,
68+ global ::System . Text . Json . JsonSerializerOptions options )
69+ {
70+ options = options ?? throw new global ::System . ArgumentNullException ( nameof ( options ) ) ;
71+ var typeInfoResolver = options . TypeInfoResolver ?? throw new global ::System . InvalidOperationException ( "TypeInfoResolver is not set." ) ;
72+
73+ if ( value . IsText )
74+ {
75+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . OutputTextContent ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . OutputTextContent ? > ??
76+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . OutputTextContent ) . Name } ") ;
77+ global ::System . Text . Json . JsonSerializer . Serialize ( writer , value . Text , typeInfo ) ;
78+ }
79+ else if ( value . IsRefusal )
80+ {
81+ var typeInfo = typeInfoResolver . GetTypeInfo ( typeof ( global ::tryAGI . OpenAI . RefusalContent ) , options ) as global ::System . Text . Json . Serialization . Metadata . JsonTypeInfo < global ::tryAGI . OpenAI . RefusalContent ? > ??
82+ throw new global ::System . InvalidOperationException ( $ "Cannot get type info for { typeof ( global ::tryAGI . OpenAI . RefusalContent ) . Name } ") ;
83+ global ::System . Text . Json . JsonSerializer . Serialize ( writer , value . Refusal , typeInfo ) ;
84+ }
85+ }
86+ }
87+ }
0 commit comments