Skip to content

Commit 49f0547

Browse files
fix(api): fix discriminator propertyName for ResponseFormatJsonSchema
1 parent 8df42ad commit 49f0547

File tree

2 files changed

+44
-26
lines changed

2 files changed

+44
-26
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 135
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-812a10f8fb54c584efc914422b574cb3f43dc238b5733b13f6a0b2308b7d9910.yml
3-
openapi_spec_hash: 0222041ba12a5ff6b94924a834fa91a2
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a4bb37d110a22c2888f53e21281434686a6fffa3e672a40f2503ad9bd2759063.yml
3+
openapi_spec_hash: 2d59eefb494dff4eea8c3d008c7e2070
44
config_hash: 50ee3382a63c021a9f821a935950e926

openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParams.kt

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)