@@ -14,6 +14,7 @@ import com.openai.core.checkRequired
14
14
import com.openai.errors.OpenAIInvalidDataException
15
15
import java.util.Collections
16
16
import java.util.Objects
17
+ import java.util.Optional
17
18
import kotlin.jvm.optionals.getOrNull
18
19
19
20
/* *
@@ -30,20 +31,20 @@ class ConversationItemCreatedEvent
30
31
private constructor (
31
32
private val eventId: JsonField <String >,
32
33
private val item: JsonField <ConversationItem >,
33
- private val previousItemId: JsonField <String >,
34
34
private val type: JsonValue ,
35
+ private val previousItemId: JsonField <String >,
35
36
private val additionalProperties: MutableMap <String , JsonValue >,
36
37
) {
37
38
38
39
@JsonCreator
39
40
private constructor (
40
41
@JsonProperty(" event_id" ) @ExcludeMissing eventId: JsonField <String > = JsonMissing .of(),
41
42
@JsonProperty(" item" ) @ExcludeMissing item: JsonField <ConversationItem > = JsonMissing .of(),
43
+ @JsonProperty(" type" ) @ExcludeMissing type: JsonValue = JsonMissing .of(),
42
44
@JsonProperty(" previous_item_id" )
43
45
@ExcludeMissing
44
46
previousItemId: JsonField <String > = JsonMissing .of(),
45
- @JsonProperty(" type" ) @ExcludeMissing type: JsonValue = JsonMissing .of(),
46
- ) : this (eventId, item, previousItemId, type, mutableMapOf ())
47
+ ) : this (eventId, item, type, previousItemId, mutableMapOf ())
47
48
48
49
/* *
49
50
* The unique ID of the server event.
@@ -61,15 +62,6 @@ private constructor(
61
62
*/
62
63
fun item (): ConversationItem = item.getRequired(" item" )
63
64
64
- /* *
65
- * The ID of the preceding item in the Conversation context, allows the client to understand the
66
- * order of the conversation.
67
- *
68
- * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
69
- * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
70
- */
71
- fun previousItemId (): String = previousItemId.getRequired(" previous_item_id" )
72
-
73
65
/* *
74
66
* The event type, must be `conversation.item.created`.
75
67
*
@@ -83,6 +75,15 @@ private constructor(
83
75
*/
84
76
@JsonProperty(" type" ) @ExcludeMissing fun _type (): JsonValue = type
85
77
78
+ /* *
79
+ * The ID of the preceding item in the Conversation context, allows the client to understand the
80
+ * order of the conversation. Can be `null` if the item has no predecessor.
81
+ *
82
+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
83
+ * server responded with an unexpected value).
84
+ */
85
+ fun previousItemId (): Optional <String > = previousItemId.getOptional(" previous_item_id" )
86
+
86
87
/* *
87
88
* Returns the raw JSON value of [eventId].
88
89
*
@@ -127,7 +128,6 @@ private constructor(
127
128
* ```java
128
129
* .eventId()
129
130
* .item()
130
- * .previousItemId()
131
131
* ```
132
132
*/
133
133
@JvmStatic fun builder () = Builder ()
@@ -138,16 +138,16 @@ private constructor(
138
138
139
139
private var eventId: JsonField <String >? = null
140
140
private var item: JsonField <ConversationItem >? = null
141
- private var previousItemId: JsonField <String >? = null
142
141
private var type: JsonValue = JsonValue .from(" conversation.item.created" )
142
+ private var previousItemId: JsonField <String > = JsonMissing .of()
143
143
private var additionalProperties: MutableMap <String , JsonValue > = mutableMapOf ()
144
144
145
145
@JvmSynthetic
146
146
internal fun from (conversationItemCreatedEvent : ConversationItemCreatedEvent ) = apply {
147
147
eventId = conversationItemCreatedEvent.eventId
148
148
item = conversationItemCreatedEvent.item
149
- previousItemId = conversationItemCreatedEvent.previousItemId
150
149
type = conversationItemCreatedEvent.type
150
+ previousItemId = conversationItemCreatedEvent.previousItemId
151
151
additionalProperties = conversationItemCreatedEvent.additionalProperties.toMutableMap()
152
152
}
153
153
@@ -174,11 +174,30 @@ private constructor(
174
174
*/
175
175
fun item (item : JsonField <ConversationItem >) = apply { this .item = item }
176
176
177
+ /* *
178
+ * Sets the field to an arbitrary JSON value.
179
+ *
180
+ * It is usually unnecessary to call this method because the field defaults to the
181
+ * following:
182
+ * ```java
183
+ * JsonValue.from("conversation.item.created")
184
+ * ```
185
+ *
186
+ * This method is primarily for setting the field to an undocumented or not yet supported
187
+ * value.
188
+ */
189
+ fun type (type : JsonValue ) = apply { this .type = type }
190
+
177
191
/* *
178
192
* The ID of the preceding item in the Conversation context, allows the client to understand
179
- * the order of the conversation.
193
+ * the order of the conversation. Can be `null` if the item has no predecessor.
180
194
*/
181
- fun previousItemId (previousItemId : String ) = previousItemId(JsonField .of(previousItemId))
195
+ fun previousItemId (previousItemId : String? ) =
196
+ previousItemId(JsonField .ofNullable(previousItemId))
197
+
198
+ /* * Alias for calling [Builder.previousItemId] with `previousItemId.orElse(null)`. */
199
+ fun previousItemId (previousItemId : Optional <String >) =
200
+ previousItemId(previousItemId.getOrNull())
182
201
183
202
/* *
184
203
* Sets [Builder.previousItemId] to an arbitrary JSON value.
@@ -191,20 +210,6 @@ private constructor(
191
210
this .previousItemId = previousItemId
192
211
}
193
212
194
- /* *
195
- * Sets the field to an arbitrary JSON value.
196
- *
197
- * It is usually unnecessary to call this method because the field defaults to the
198
- * following:
199
- * ```java
200
- * JsonValue.from("conversation.item.created")
201
- * ```
202
- *
203
- * This method is primarily for setting the field to an undocumented or not yet supported
204
- * value.
205
- */
206
- fun type (type : JsonValue ) = apply { this .type = type }
207
-
208
213
fun additionalProperties (additionalProperties : Map <String , JsonValue >) = apply {
209
214
this .additionalProperties.clear()
210
215
putAllAdditionalProperties(additionalProperties)
@@ -233,7 +238,6 @@ private constructor(
233
238
* ```java
234
239
* .eventId()
235
240
* .item()
236
- * .previousItemId()
237
241
* ```
238
242
*
239
243
* @throws IllegalStateException if any required field is unset.
@@ -242,8 +246,8 @@ private constructor(
242
246
ConversationItemCreatedEvent (
243
247
checkRequired(" eventId" , eventId),
244
248
checkRequired(" item" , item),
245
- checkRequired(" previousItemId" , previousItemId),
246
249
type,
250
+ previousItemId,
247
251
additionalProperties.toMutableMap(),
248
252
)
249
253
}
@@ -257,12 +261,12 @@ private constructor(
257
261
258
262
eventId()
259
263
item().validate()
260
- previousItemId()
261
264
_type ().let {
262
265
if (it != JsonValue .from(" conversation.item.created" )) {
263
266
throw OpenAIInvalidDataException (" 'type' is invalid, received $it " )
264
267
}
265
268
}
269
+ previousItemId()
266
270
validated = true
267
271
}
268
272
@@ -283,23 +287,23 @@ private constructor(
283
287
internal fun validity (): Int =
284
288
(if (eventId.asKnown().isPresent) 1 else 0 ) +
285
289
(item.asKnown().getOrNull()?.validity() ? : 0 ) +
286
- ( if (previousItemId.asKnown().isPresent) 1 else 0 ) +
287
- type. let { if (it == JsonValue .from( " conversation.item.created " )) 1 else 0 }
290
+ type. let { if (it == JsonValue .from( " conversation.item.created " )) 1 else 0 } +
291
+ ( if (previousItemId.asKnown().isPresent) 1 else 0 )
288
292
289
293
override fun equals (other : Any? ): Boolean {
290
294
if (this == = other) {
291
295
return true
292
296
}
293
297
294
- return /* spotless:off */ other is ConversationItemCreatedEvent && eventId == other.eventId && item == other.item && previousItemId == other.previousItemId && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
298
+ return /* spotless:off */ other is ConversationItemCreatedEvent && eventId == other.eventId && item == other.item && type == other.type && previousItemId == other.previousItemId && additionalProperties == other.additionalProperties /* spotless:on */
295
299
}
296
300
297
301
/* spotless:off */
298
- private val hashCode: Int by lazy { Objects .hash(eventId, item, previousItemId, type , additionalProperties) }
302
+ private val hashCode: Int by lazy { Objects .hash(eventId, item, type, previousItemId , additionalProperties) }
299
303
/* spotless:on */
300
304
301
305
override fun hashCode (): Int = hashCode
302
306
303
307
override fun toString () =
304
- " ConversationItemCreatedEvent{eventId=$eventId , item=$item , previousItemId= $previousItemId , type= $type , additionalProperties=$additionalProperties }"
308
+ " ConversationItemCreatedEvent{eventId=$eventId , item=$item , type= $type , previousItemId= $previousItemId , additionalProperties=$additionalProperties }"
305
309
}
0 commit comments