Skip to content

Commit f1733f8

Browse files
fix(api): fix nullability of logprobs
Makes ResponseOutputText.logprobs nullable, matching with 2.6.1. While this is always present in the server response, this inadvertently affected params and some constructors
1 parent abb7fe4 commit f1733f8

20 files changed

+121
-122
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-3c5d1593d7c6f2b38a7d78d7906041465ee9d6e9022f0651e1da194654488108.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-eeba8addf3a5f412e5ce8d22031e60c61650cee3f5d9e587a2533f6818a249ea.yml
33
openapi_spec_hash: 0a4d8ad2469823ce24a3fd94f23f1c2b
4-
config_hash: 032995825500a503a76da119f5354905
4+
config_hash: 0bb1941a78ece0b610a2fbba7d74a84c

openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseOutputText.kt

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class ResponseOutputText
3434
@JsonCreator(mode = JsonCreator.Mode.DISABLED)
3535
private constructor(
3636
private val annotations: JsonField<List<Annotation>>,
37-
private val logprobs: JsonField<List<Logprob>>,
3837
private val text: JsonField<String>,
3938
private val type: JsonValue,
39+
private val logprobs: JsonField<List<Logprob>>,
4040
private val additionalProperties: MutableMap<String, JsonValue>,
4141
) {
4242

@@ -45,12 +45,12 @@ private constructor(
4545
@JsonProperty("annotations")
4646
@ExcludeMissing
4747
annotations: JsonField<List<Annotation>> = JsonMissing.of(),
48+
@JsonProperty("text") @ExcludeMissing text: JsonField<String> = JsonMissing.of(),
49+
@JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
4850
@JsonProperty("logprobs")
4951
@ExcludeMissing
5052
logprobs: JsonField<List<Logprob>> = JsonMissing.of(),
51-
@JsonProperty("text") @ExcludeMissing text: JsonField<String> = JsonMissing.of(),
52-
@JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
53-
) : this(annotations, logprobs, text, type, mutableMapOf())
53+
) : this(annotations, text, type, logprobs, mutableMapOf())
5454

5555
/**
5656
* The annotations of the text output.
@@ -60,12 +60,6 @@ private constructor(
6060
*/
6161
fun annotations(): List<Annotation> = annotations.getRequired("annotations")
6262

63-
/**
64-
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
65-
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
66-
*/
67-
fun logprobs(): List<Logprob> = logprobs.getRequired("logprobs")
68-
6963
/**
7064
* The text output from the model.
7165
*
@@ -87,6 +81,12 @@ private constructor(
8781
*/
8882
@JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type
8983

84+
/**
85+
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
86+
* server responded with an unexpected value).
87+
*/
88+
fun logprobs(): Optional<List<Logprob>> = logprobs.getOptional("logprobs")
89+
9090
/**
9191
* Returns the raw JSON value of [annotations].
9292
*
@@ -97,18 +97,18 @@ private constructor(
9797
fun _annotations(): JsonField<List<Annotation>> = annotations
9898

9999
/**
100-
* Returns the raw JSON value of [logprobs].
100+
* Returns the raw JSON value of [text].
101101
*
102-
* Unlike [logprobs], this method doesn't throw if the JSON field has an unexpected type.
102+
* Unlike [text], this method doesn't throw if the JSON field has an unexpected type.
103103
*/
104-
@JsonProperty("logprobs") @ExcludeMissing fun _logprobs(): JsonField<List<Logprob>> = logprobs
104+
@JsonProperty("text") @ExcludeMissing fun _text(): JsonField<String> = text
105105

106106
/**
107-
* Returns the raw JSON value of [text].
107+
* Returns the raw JSON value of [logprobs].
108108
*
109-
* Unlike [text], this method doesn't throw if the JSON field has an unexpected type.
109+
* Unlike [logprobs], this method doesn't throw if the JSON field has an unexpected type.
110110
*/
111-
@JsonProperty("text") @ExcludeMissing fun _text(): JsonField<String> = text
111+
@JsonProperty("logprobs") @ExcludeMissing fun _logprobs(): JsonField<List<Logprob>> = logprobs
112112

113113
@JsonAnySetter
114114
private fun putAdditionalProperty(key: String, value: JsonValue) {
@@ -130,7 +130,6 @@ private constructor(
130130
* The following fields are required:
131131
* ```java
132132
* .annotations()
133-
* .logprobs()
134133
* .text()
135134
* ```
136135
*/
@@ -141,17 +140,17 @@ private constructor(
141140
class Builder internal constructor() {
142141

143142
private var annotations: JsonField<MutableList<Annotation>>? = null
144-
private var logprobs: JsonField<MutableList<Logprob>>? = null
145143
private var text: JsonField<String>? = null
146144
private var type: JsonValue = JsonValue.from("output_text")
145+
private var logprobs: JsonField<MutableList<Logprob>>? = null
147146
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
148147

149148
@JvmSynthetic
150149
internal fun from(responseOutputText: ResponseOutputText) = apply {
151150
annotations = responseOutputText.annotations.map { it.toMutableList() }
152-
logprobs = responseOutputText.logprobs.map { it.toMutableList() }
153151
text = responseOutputText.text
154152
type = responseOutputText.type
153+
logprobs = responseOutputText.logprobs.map { it.toMutableList() }
155154
additionalProperties = responseOutputText.additionalProperties.toMutableMap()
156155
}
157156

@@ -200,31 +199,6 @@ private constructor(
200199
fun addAnnotation(filePath: Annotation.FilePath) =
201200
addAnnotation(Annotation.ofFilePath(filePath))
202201

203-
fun logprobs(logprobs: List<Logprob>) = logprobs(JsonField.of(logprobs))
204-
205-
/**
206-
* Sets [Builder.logprobs] to an arbitrary JSON value.
207-
*
208-
* You should usually call [Builder.logprobs] with a well-typed `List<Logprob>` value
209-
* instead. This method is primarily for setting the field to an undocumented or not yet
210-
* supported value.
211-
*/
212-
fun logprobs(logprobs: JsonField<List<Logprob>>) = apply {
213-
this.logprobs = logprobs.map { it.toMutableList() }
214-
}
215-
216-
/**
217-
* Adds a single [Logprob] to [logprobs].
218-
*
219-
* @throws IllegalStateException if the field was previously set to a non-list.
220-
*/
221-
fun addLogprob(logprob: Logprob) = apply {
222-
logprobs =
223-
(logprobs ?: JsonField.of(mutableListOf())).also {
224-
checkKnown("logprobs", it).add(logprob)
225-
}
226-
}
227-
228202
/** The text output from the model. */
229203
fun text(text: String) = text(JsonField.of(text))
230204

@@ -250,6 +224,31 @@ private constructor(
250224
*/
251225
fun type(type: JsonValue) = apply { this.type = type }
252226

227+
fun logprobs(logprobs: List<Logprob>) = logprobs(JsonField.of(logprobs))
228+
229+
/**
230+
* Sets [Builder.logprobs] to an arbitrary JSON value.
231+
*
232+
* You should usually call [Builder.logprobs] with a well-typed `List<Logprob>` value
233+
* instead. This method is primarily for setting the field to an undocumented or not yet
234+
* supported value.
235+
*/
236+
fun logprobs(logprobs: JsonField<List<Logprob>>) = apply {
237+
this.logprobs = logprobs.map { it.toMutableList() }
238+
}
239+
240+
/**
241+
* Adds a single [Logprob] to [logprobs].
242+
*
243+
* @throws IllegalStateException if the field was previously set to a non-list.
244+
*/
245+
fun addLogprob(logprob: Logprob) = apply {
246+
logprobs =
247+
(logprobs ?: JsonField.of(mutableListOf())).also {
248+
checkKnown("logprobs", it).add(logprob)
249+
}
250+
}
251+
253252
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
254253
this.additionalProperties.clear()
255254
putAllAdditionalProperties(additionalProperties)
@@ -277,7 +276,6 @@ private constructor(
277276
* The following fields are required:
278277
* ```java
279278
* .annotations()
280-
* .logprobs()
281279
* .text()
282280
* ```
283281
*
@@ -286,9 +284,9 @@ private constructor(
286284
fun build(): ResponseOutputText =
287285
ResponseOutputText(
288286
checkRequired("annotations", annotations).map { it.toImmutable() },
289-
checkRequired("logprobs", logprobs).map { it.toImmutable() },
290287
checkRequired("text", text),
291288
type,
289+
(logprobs ?: JsonMissing.of()).map { it.toImmutable() },
292290
additionalProperties.toMutableMap(),
293291
)
294292
}
@@ -301,13 +299,13 @@ private constructor(
301299
}
302300

303301
annotations().forEach { it.validate() }
304-
logprobs().forEach { it.validate() }
305302
text()
306303
_type().let {
307304
if (it != JsonValue.from("output_text")) {
308305
throw OpenAIInvalidDataException("'type' is invalid, received $it")
309306
}
310307
}
308+
logprobs().ifPresent { it.forEach { it.validate() } }
311309
validated = true
312310
}
313311

@@ -327,9 +325,9 @@ private constructor(
327325
@JvmSynthetic
328326
internal fun validity(): Int =
329327
(annotations.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
330-
(logprobs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
331328
(if (text.asKnown().isPresent) 1 else 0) +
332-
type.let { if (it == JsonValue.from("output_text")) 1 else 0 }
329+
type.let { if (it == JsonValue.from("output_text")) 1 else 0 } +
330+
(logprobs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)
333331

334332
/** A citation to a file. */
335333
@JsonDeserialize(using = Annotation.Deserializer::class)
@@ -2394,18 +2392,18 @@ private constructor(
23942392

23952393
return other is ResponseOutputText &&
23962394
annotations == other.annotations &&
2397-
logprobs == other.logprobs &&
23982395
text == other.text &&
23992396
type == other.type &&
2397+
logprobs == other.logprobs &&
24002398
additionalProperties == other.additionalProperties
24012399
}
24022400

24032401
private val hashCode: Int by lazy {
2404-
Objects.hash(annotations, logprobs, text, type, additionalProperties)
2402+
Objects.hash(annotations, text, type, logprobs, additionalProperties)
24052403
}
24062404

24072405
override fun hashCode(): Int = hashCode
24082406

24092407
override fun toString() =
2410-
"ResponseOutputText{annotations=$annotations, logprobs=$logprobs, text=$text, type=$type, additionalProperties=$additionalProperties}"
2408+
"ResponseOutputText{annotations=$annotations, text=$text, type=$type, logprobs=$logprobs, additionalProperties=$additionalProperties}"
24112409
}

openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseCompletedEventTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ internal class ResponseCompletedEventTest {
5252
.index(0L)
5353
.build()
5454
)
55+
.text("text")
5556
.addLogprob(
5657
ResponseOutputText.Logprob.builder()
5758
.token("token")
@@ -66,7 +67,6 @@ internal class ResponseCompletedEventTest {
6667
)
6768
.build()
6869
)
69-
.text("text")
7070
.build()
7171
)
7272
.status(ResponseOutputMessage.Status.IN_PROGRESS)
@@ -181,6 +181,7 @@ internal class ResponseCompletedEventTest {
181181
.index(0L)
182182
.build()
183183
)
184+
.text("text")
184185
.addLogprob(
185186
ResponseOutputText.Logprob.builder()
186187
.token("token")
@@ -195,7 +196,6 @@ internal class ResponseCompletedEventTest {
195196
)
196197
.build()
197198
)
198-
.text("text")
199199
.build()
200200
)
201201
.status(ResponseOutputMessage.Status.IN_PROGRESS)
@@ -312,6 +312,7 @@ internal class ResponseCompletedEventTest {
312312
.index(0L)
313313
.build()
314314
)
315+
.text("text")
315316
.addLogprob(
316317
ResponseOutputText.Logprob.builder()
317318
.token("token")
@@ -326,7 +327,6 @@ internal class ResponseCompletedEventTest {
326327
)
327328
.build()
328329
)
329-
.text("text")
330330
.build()
331331
)
332332
.status(ResponseOutputMessage.Status.IN_PROGRESS)

openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContentPartAddedEventTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ internal class ResponseContentPartAddedEventTest {
2525
.index(0L)
2626
.build()
2727
)
28+
.text("text")
2829
.addLogprob(
2930
ResponseOutputText.Logprob.builder()
3031
.token("token")
@@ -39,7 +40,6 @@ internal class ResponseContentPartAddedEventTest {
3940
)
4041
.build()
4142
)
42-
.text("text")
4343
.build()
4444
)
4545
.sequenceNumber(0L)
@@ -59,6 +59,7 @@ internal class ResponseContentPartAddedEventTest {
5959
.index(0L)
6060
.build()
6161
)
62+
.text("text")
6263
.addLogprob(
6364
ResponseOutputText.Logprob.builder()
6465
.token("token")
@@ -73,7 +74,6 @@ internal class ResponseContentPartAddedEventTest {
7374
)
7475
.build()
7576
)
76-
.text("text")
7777
.build()
7878
)
7979
)
@@ -97,6 +97,7 @@ internal class ResponseContentPartAddedEventTest {
9797
.index(0L)
9898
.build()
9999
)
100+
.text("text")
100101
.addLogprob(
101102
ResponseOutputText.Logprob.builder()
102103
.token("token")
@@ -111,7 +112,6 @@ internal class ResponseContentPartAddedEventTest {
111112
)
112113
.build()
113114
)
114-
.text("text")
115115
.build()
116116
)
117117
.sequenceNumber(0L)

openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseContentPartDoneEventTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ internal class ResponseContentPartDoneEventTest {
2525
.index(0L)
2626
.build()
2727
)
28+
.text("text")
2829
.addLogprob(
2930
ResponseOutputText.Logprob.builder()
3031
.token("token")
@@ -39,7 +40,6 @@ internal class ResponseContentPartDoneEventTest {
3940
)
4041
.build()
4142
)
42-
.text("text")
4343
.build()
4444
)
4545
.sequenceNumber(0L)
@@ -59,6 +59,7 @@ internal class ResponseContentPartDoneEventTest {
5959
.index(0L)
6060
.build()
6161
)
62+
.text("text")
6263
.addLogprob(
6364
ResponseOutputText.Logprob.builder()
6465
.token("token")
@@ -73,7 +74,6 @@ internal class ResponseContentPartDoneEventTest {
7374
)
7475
.build()
7576
)
76-
.text("text")
7777
.build()
7878
)
7979
)
@@ -97,6 +97,7 @@ internal class ResponseContentPartDoneEventTest {
9797
.index(0L)
9898
.build()
9999
)
100+
.text("text")
100101
.addLogprob(
101102
ResponseOutputText.Logprob.builder()
102103
.token("token")
@@ -111,7 +112,6 @@ internal class ResponseContentPartDoneEventTest {
111112
)
112113
.build()
113114
)
114-
.text("text")
115115
.build()
116116
)
117117
.sequenceNumber(0L)

0 commit comments

Comments
 (0)