66import com .azure .core .annotation .Fluent ;
77import com .azure .core .annotation .Generated ;
88import com .azure .core .util .BinaryData ;
9+ import com .azure .core .util .CoreUtils ;
910import com .azure .json .JsonReader ;
1011import com .azure .json .JsonToken ;
1112import com .azure .json .JsonWriter ;
1213import java .io .IOException ;
14+ import java .util .Arrays ;
15+ import java .util .List ;
1316
1417/**
1518 * Developer-provided instructions that the model should follow, regardless of messages sent by the user.
@@ -30,6 +33,10 @@ public final class ChatRequestDeveloperMessage extends ChatRequestMessage {
3033 @ Generated
3134 private final BinaryData content ;
3235
36+ private final String stringContent ;
37+
38+ private final List <ChatMessageContentItem > chatMessageContentItems ;
39+
3340 /*
3441 * An optional name for the participant. Provides the model information to differentiate between participants of the
3542 * same role.
@@ -42,9 +49,43 @@ public final class ChatRequestDeveloperMessage extends ChatRequestMessage {
4249 *
4350 * @param content the content value to set.
4451 */
45- @ Generated
46- public ChatRequestDeveloperMessage (BinaryData content ) {
52+ private ChatRequestDeveloperMessage (BinaryData content ) {
4753 this .content = content ;
54+ this .stringContent = null ;
55+ this .chatMessageContentItems = null ;
56+ }
57+
58+ /**
59+ * Creates an instance of ChatRequestDeveloperMessage class.
60+ *
61+ * @param content the content value to set.
62+ */
63+ public ChatRequestDeveloperMessage (String content ) {
64+ this .content = BinaryData .fromString (content );
65+ this .stringContent = content ;
66+ this .chatMessageContentItems = null ;
67+ }
68+
69+ /**
70+ * Creates an instance of ChatRequestDeveloperMessage class.
71+ *
72+ * @param content the content value to set.
73+ */
74+ public ChatRequestDeveloperMessage (List <ChatMessageContentItem > content ) {
75+ this .content = BinaryData .fromObject (content );
76+ this .stringContent = null ;
77+ this .chatMessageContentItems = content ;
78+ }
79+
80+ /**
81+ * Creates a new instance of ChatRequestDeveloperMessage using a collection of structured content.
82+ *
83+ * @param content The collection of structured content associated with the message.
84+ */
85+ public ChatRequestDeveloperMessage (ChatMessageContentItem [] content ) {
86+ this .content = BinaryData .fromObject (content );
87+ this .chatMessageContentItems = Arrays .asList (content );
88+ this .stringContent = null ;
4889 }
4990
5091 /**
@@ -69,6 +110,38 @@ public BinaryData getContent() {
69110 return this .content ;
70111 }
71112
113+ /**
114+ * Get the content property: The contents of the user message, with available input types varying by selected model.
115+ * If the result of this method is `null`, it means that the content could be a String or null altogether.
116+ *
117+ * @return the content value if defined as a list
118+ */
119+ public List <ChatMessageContentItem > getListContent () {
120+ return this .chatMessageContentItems ;
121+ }
122+
123+ /**
124+ * Get the content property: The contents of the user message, with available input types varying by selected model.
125+ * If the result of this method is `null`, it means that the content could be a String or null altogether.
126+ *
127+ * @return the content value if defined as an array
128+ */
129+ public ChatMessageContentItem [] getArrayContent () {
130+ return this .chatMessageContentItems == null
131+ ? null
132+ : this .chatMessageContentItems .toArray (new ChatMessageContentItem [0 ]);
133+ }
134+
135+ /**
136+ * Get the content property: The contents of the user message, with available input types varying by selected model.
137+ * If the result of this method is `null`, it means that the content could be a list or null altogether.
138+ *
139+ * @return the content value if defined as a string
140+ */
141+ public String getStringContent () {
142+ return this .stringContent ;
143+ }
144+
72145 /**
73146 * Get the name property: An optional name for the participant. Provides the model information to differentiate
74147 * between participants of the same role.
@@ -96,12 +169,16 @@ public ChatRequestDeveloperMessage setName(String name) {
96169 /**
97170 * {@inheritDoc}
98171 */
99- @ Generated
100172 @ Override
101173 public JsonWriter toJson (JsonWriter jsonWriter ) throws IOException {
102174 jsonWriter .writeStartObject ();
103- jsonWriter .writeFieldName ("content" );
104- this .content .writeTo (jsonWriter );
175+ if (stringContent != null ) {
176+ jsonWriter .writeStringField ("content" , stringContent );
177+ } else if (chatMessageContentItems != null ) {
178+ jsonWriter .writeArrayField ("content" , chatMessageContentItems , JsonWriter ::writeJson );
179+ } else {
180+ jsonWriter .writeNullField ("content" );
181+ }
105182 jsonWriter .writeStringField ("role" , this .role == null ? null : this .role .toString ());
106183 jsonWriter .writeStringField ("name" , this .name );
107184 return jsonWriter .writeEndObject ();
@@ -116,17 +193,28 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
116193 * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
117194 * @throws IOException If an error occurs while reading the ChatRequestDeveloperMessage.
118195 */
119- @ Generated
120196 public static ChatRequestDeveloperMessage fromJson (JsonReader jsonReader ) throws IOException {
121197 return jsonReader .readObject (reader -> {
122198 BinaryData content = null ;
199+ String stringContent = null ;
200+ List <ChatMessageContentItem > chatMessageContentItems = null ;
123201 ChatRole role = ChatRole .DEVELOPER ;
124202 String name = null ;
125203 while (reader .nextToken () != JsonToken .END_OBJECT ) {
126204 String fieldName = reader .getFieldName ();
127205 reader .nextToken ();
128206 if ("content" .equals (fieldName )) {
129- content = reader .getNullable (nonNullReader -> BinaryData .fromObject (nonNullReader .readUntyped ()));
207+ if (reader .currentToken () == JsonToken .STRING ) {
208+ stringContent = reader .getString ();
209+ } else if (reader .currentToken () == JsonToken .START_ARRAY ) {
210+ chatMessageContentItems
211+ = reader .readArray (arrayReader -> arrayReader .readObject (ChatMessageContentItem ::fromJson ));
212+ } else if (reader .currentToken () == JsonToken .NULL ) {
213+ content = null ;
214+ } else {
215+ throw new IllegalStateException ("Unexpected 'content' type found when deserializing"
216+ + " ChatRequestAssistantMessage JSON object: " + reader .currentToken ());
217+ }
130218 } else if ("role" .equals (fieldName )) {
131219 role = ChatRole .fromString (reader .getString ());
132220 } else if ("name" .equals (fieldName )) {
@@ -135,8 +223,14 @@ public static ChatRequestDeveloperMessage fromJson(JsonReader jsonReader) throws
135223 reader .skipChildren ();
136224 }
137225 }
138- ChatRequestDeveloperMessage deserializedChatRequestDeveloperMessage
139- = new ChatRequestDeveloperMessage (content );
226+ ChatRequestDeveloperMessage deserializedChatRequestDeveloperMessage ;
227+ if (CoreUtils .isNullOrEmpty (stringContent ) && chatMessageContentItems == null ) {
228+ deserializedChatRequestDeveloperMessage = new ChatRequestDeveloperMessage (content );
229+ } else {
230+ deserializedChatRequestDeveloperMessage = CoreUtils .isNullOrEmpty (stringContent )
231+ ? new ChatRequestDeveloperMessage (chatMessageContentItems )
232+ : new ChatRequestDeveloperMessage (stringContent );
233+ }
140234 deserializedChatRequestDeveloperMessage .role = role ;
141235 deserializedChatRequestDeveloperMessage .name = name ;
142236 return deserializedChatRequestDeveloperMessage ;
0 commit comments