@@ -1406,6 +1406,18 @@ private constructor(
14061406 body.responseFormat(jsonSchema)
14071407 }
14081408
1409+ /* *
1410+ * Alias for calling [responseFormat] with the following:
1411+ * ```java
1412+ * ResponseFormatJsonSchema.builder()
1413+ * .jsonSchema(jsonSchema)
1414+ * .build()
1415+ * ```
1416+ */
1417+ fun jsonSchemaResponseFormat (jsonSchema : ResponseFormatJsonSchema .JsonSchema ) = apply {
1418+ body.jsonSchemaResponseFormat(jsonSchema)
1419+ }
1420+
14091421 /* * Alias for calling [responseFormat] with `ResponseFormat.ofJsonObject(jsonObject)`. */
14101422 fun responseFormat (jsonObject : ResponseFormatJsonObject ) = apply {
14111423 body.responseFormat(jsonObject)
@@ -3665,6 +3677,17 @@ private constructor(
36653677 fun responseFormat (jsonSchema : ResponseFormatJsonSchema ) =
36663678 responseFormat(ResponseFormat .ofJsonSchema(jsonSchema))
36673679
3680+ /* *
3681+ * Alias for calling [responseFormat] with the following:
3682+ * ```java
3683+ * ResponseFormatJsonSchema.builder()
3684+ * .jsonSchema(jsonSchema)
3685+ * .build()
3686+ * ```
3687+ */
3688+ fun jsonSchemaResponseFormat (jsonSchema : ResponseFormatJsonSchema .JsonSchema ) =
3689+ responseFormat(ResponseFormatJsonSchema .builder().jsonSchema(jsonSchema).build())
3690+
36683691 /* *
36693692 * Alias for calling [responseFormat] with `ResponseFormat.ofJsonObject(jsonObject)`.
36703693 */
@@ -5515,32 +5538,27 @@ private constructor(
55155538
55165539 override fun ObjectCodec.deserialize (node : JsonNode ): ResponseFormat {
55175540 val json = JsonValue .fromJsonNode(node)
5541+ val type = json.asObject().getOrNull()?.get(" type" )?.asString()?.getOrNull()
55185542
5519- val bestMatches =
5520- sequenceOf(
5521- tryDeserialize(node, jacksonTypeRef<ResponseFormatText >())?.let {
5522- ResponseFormat (text = it, _json = json)
5523- },
5524- tryDeserialize(node, jacksonTypeRef<ResponseFormatJsonSchema >())?.let {
5525- ResponseFormat (jsonSchema = it, _json = json)
5526- },
5527- tryDeserialize(node, jacksonTypeRef<ResponseFormatJsonObject >())?.let {
5528- ResponseFormat (jsonObject = it, _json = json)
5529- },
5530- )
5531- .filterNotNull()
5532- .allMaxBy { it.validity() }
5533- .toList()
5534- return when (bestMatches.size) {
5535- // This can happen if what we're deserializing is completely incompatible with
5536- // all the possible variants (e.g. deserializing from boolean).
5537- 0 -> ResponseFormat (_json = json)
5538- 1 -> bestMatches.single()
5539- // If there's more than one match with the highest validity, then use the first
5540- // completely valid match, or simply the first match if none are completely
5541- // valid.
5542- else -> bestMatches.firstOrNull { it.isValid() } ? : bestMatches.first()
5543+ when (type) {
5544+ " text" -> {
5545+ return tryDeserialize(node, jacksonTypeRef<ResponseFormatText >())?.let {
5546+ ResponseFormat (text = it, _json = json)
5547+ } ? : ResponseFormat (_json = json)
5548+ }
5549+ " json_schema" -> {
5550+ return tryDeserialize(node, jacksonTypeRef<ResponseFormatJsonSchema >())
5551+ ?.let { ResponseFormat (jsonSchema = it, _json = json) }
5552+ ? : ResponseFormat (_json = json)
5553+ }
5554+ " json_object" -> {
5555+ return tryDeserialize(node, jacksonTypeRef<ResponseFormatJsonObject >())
5556+ ?.let { ResponseFormat (jsonObject = it, _json = json) }
5557+ ? : ResponseFormat (_json = json)
5558+ }
55435559 }
5560+
5561+ return ResponseFormat (_json = json)
55445562 }
55455563 }
55465564
0 commit comments