Skip to content

Commit 6932929

Browse files
feat(api): add reasoning_text
1 parent fea62a3 commit 6932929

File tree

10 files changed

+1067
-19
lines changed

10 files changed

+1067
-19
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 118
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-380330a93b5d010391ca3b36ea193c5353b0dfdf2ddd02789ef84a84ce427e82.yml
3-
openapi_spec_hash: 859703234259ecdd2a3c6f4de88eb504
4-
config_hash: b619b45c1e7facf819f902dee8fa4f97
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-ea23db36b0899cc715f56d0098956069b2d92880f448adff3a4ac1bb53cb2cec.yml
3+
openapi_spec_hash: 36f76ea31297c9593bcfae453f6255cc
4+
config_hash: 666d6bb4b564f0d9d431124b5d1a0665

openai-java-core/src/main/kotlin/com/openai/models/conversations/Message.kt

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ private constructor(
263263
fun addSummaryTextContent(text: String) =
264264
addContent(SummaryTextContent.builder().text(text).build())
265265

266+
/** Alias for calling [addContent] with `Content.ofReasoningText(reasoningText)`. */
267+
fun addContent(reasoningText: Content.ReasoningText) =
268+
addContent(Content.ofReasoningText(reasoningText))
269+
270+
/**
271+
* Alias for calling [addContent] with the following:
272+
* ```java
273+
* Content.ReasoningText.builder()
274+
* .text(text)
275+
* .build()
276+
* ```
277+
*/
278+
fun addReasoningTextContent(text: String) =
279+
addContent(Content.ReasoningText.builder().text(text).build())
280+
266281
/** Alias for calling [addContent] with `Content.ofRefusal(refusal)`. */
267282
fun addContent(refusal: ResponseOutputRefusal) = addContent(Content.ofRefusal(refusal))
268283

@@ -437,6 +452,7 @@ private constructor(
437452
private val outputText: ResponseOutputText? = null,
438453
private val text: TextContent? = null,
439454
private val summaryText: SummaryTextContent? = null,
455+
private val reasoningText: ReasoningText? = null,
440456
private val refusal: ResponseOutputRefusal? = null,
441457
private val inputImage: ResponseInputImage? = null,
442458
private val computerScreenshot: ComputerScreenshotContent? = null,
@@ -456,6 +472,9 @@ private constructor(
456472
/** A summary text from the model. */
457473
fun summaryText(): Optional<SummaryTextContent> = Optional.ofNullable(summaryText)
458474

475+
/** Reasoning text from the model. */
476+
fun reasoningText(): Optional<ReasoningText> = Optional.ofNullable(reasoningText)
477+
459478
/** A refusal from the model. */
460479
fun refusal(): Optional<ResponseOutputRefusal> = Optional.ofNullable(refusal)
461480

@@ -480,6 +499,8 @@ private constructor(
480499

481500
fun isSummaryText(): Boolean = summaryText != null
482501

502+
fun isReasoningText(): Boolean = reasoningText != null
503+
483504
fun isRefusal(): Boolean = refusal != null
484505

485506
fun isInputImage(): Boolean = inputImage != null
@@ -500,6 +521,9 @@ private constructor(
500521
/** A summary text from the model. */
501522
fun asSummaryText(): SummaryTextContent = summaryText.getOrThrow("summaryText")
502523

524+
/** Reasoning text from the model. */
525+
fun asReasoningText(): ReasoningText = reasoningText.getOrThrow("reasoningText")
526+
503527
/** A refusal from the model. */
504528
fun asRefusal(): ResponseOutputRefusal = refusal.getOrThrow("refusal")
505529

@@ -524,6 +548,7 @@ private constructor(
524548
outputText != null -> visitor.visitOutputText(outputText)
525549
text != null -> visitor.visitText(text)
526550
summaryText != null -> visitor.visitSummaryText(summaryText)
551+
reasoningText != null -> visitor.visitReasoningText(reasoningText)
527552
refusal != null -> visitor.visitRefusal(refusal)
528553
inputImage != null -> visitor.visitInputImage(inputImage)
529554
computerScreenshot != null -> visitor.visitComputerScreenshot(computerScreenshot)
@@ -556,6 +581,10 @@ private constructor(
556581
summaryText.validate()
557582
}
558583

584+
override fun visitReasoningText(reasoningText: ReasoningText) {
585+
reasoningText.validate()
586+
}
587+
559588
override fun visitRefusal(refusal: ResponseOutputRefusal) {
560589
refusal.validate()
561590
}
@@ -606,6 +635,9 @@ private constructor(
606635
override fun visitSummaryText(summaryText: SummaryTextContent) =
607636
summaryText.validity()
608637

638+
override fun visitReasoningText(reasoningText: ReasoningText) =
639+
reasoningText.validity()
640+
609641
override fun visitRefusal(refusal: ResponseOutputRefusal) = refusal.validity()
610642

611643
override fun visitInputImage(inputImage: ResponseInputImage) =
@@ -631,6 +663,7 @@ private constructor(
631663
outputText == other.outputText &&
632664
text == other.text &&
633665
summaryText == other.summaryText &&
666+
reasoningText == other.reasoningText &&
634667
refusal == other.refusal &&
635668
inputImage == other.inputImage &&
636669
computerScreenshot == other.computerScreenshot &&
@@ -643,6 +676,7 @@ private constructor(
643676
outputText,
644677
text,
645678
summaryText,
679+
reasoningText,
646680
refusal,
647681
inputImage,
648682
computerScreenshot,
@@ -655,6 +689,7 @@ private constructor(
655689
outputText != null -> "Content{outputText=$outputText}"
656690
text != null -> "Content{text=$text}"
657691
summaryText != null -> "Content{summaryText=$summaryText}"
692+
reasoningText != null -> "Content{reasoningText=$reasoningText}"
658693
refusal != null -> "Content{refusal=$refusal}"
659694
inputImage != null -> "Content{inputImage=$inputImage}"
660695
computerScreenshot != null -> "Content{computerScreenshot=$computerScreenshot}"
@@ -680,6 +715,11 @@ private constructor(
680715
@JvmStatic
681716
fun ofSummaryText(summaryText: SummaryTextContent) = Content(summaryText = summaryText)
682717

718+
/** Reasoning text from the model. */
719+
@JvmStatic
720+
fun ofReasoningText(reasoningText: ReasoningText) =
721+
Content(reasoningText = reasoningText)
722+
683723
/** A refusal from the model. */
684724
@JvmStatic fun ofRefusal(refusal: ResponseOutputRefusal) = Content(refusal = refusal)
685725

@@ -717,6 +757,9 @@ private constructor(
717757
/** A summary text from the model. */
718758
fun visitSummaryText(summaryText: SummaryTextContent): T
719759

760+
/** Reasoning text from the model. */
761+
fun visitReasoningText(reasoningText: ReasoningText): T
762+
720763
/** A refusal from the model. */
721764
fun visitRefusal(refusal: ResponseOutputRefusal): T
722765

@@ -774,6 +817,11 @@ private constructor(
774817
Content(summaryText = it, _json = json)
775818
} ?: Content(_json = json)
776819
}
820+
"reasoning_text" -> {
821+
return tryDeserialize(node, jacksonTypeRef<ReasoningText>())?.let {
822+
Content(reasoningText = it, _json = json)
823+
} ?: Content(_json = json)
824+
}
777825
"refusal" -> {
778826
return tryDeserialize(node, jacksonTypeRef<ResponseOutputRefusal>())?.let {
779827
Content(refusal = it, _json = json)
@@ -812,6 +860,7 @@ private constructor(
812860
value.outputText != null -> generator.writeObject(value.outputText)
813861
value.text != null -> generator.writeObject(value.text)
814862
value.summaryText != null -> generator.writeObject(value.summaryText)
863+
value.reasoningText != null -> generator.writeObject(value.reasoningText)
815864
value.refusal != null -> generator.writeObject(value.refusal)
816865
value.inputImage != null -> generator.writeObject(value.inputImage)
817866
value.computerScreenshot != null ->
@@ -822,6 +871,210 @@ private constructor(
822871
}
823872
}
824873
}
874+
875+
/** Reasoning text from the model. */
876+
class ReasoningText
877+
private constructor(
878+
private val text: JsonField<String>,
879+
private val type: JsonValue,
880+
private val additionalProperties: MutableMap<String, JsonValue>,
881+
) {
882+
883+
@JsonCreator
884+
private constructor(
885+
@JsonProperty("text") @ExcludeMissing text: JsonField<String> = JsonMissing.of(),
886+
@JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
887+
) : this(text, type, mutableMapOf())
888+
889+
/**
890+
* The reasoning text from the model.
891+
*
892+
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
893+
* unexpectedly missing or null (e.g. if the server responded with an unexpected
894+
* value).
895+
*/
896+
fun text(): String = text.getRequired("text")
897+
898+
/**
899+
* The type of the reasoning text. Always `reasoning_text`.
900+
*
901+
* Expected to always return the following:
902+
* ```java
903+
* JsonValue.from("reasoning_text")
904+
* ```
905+
*
906+
* However, this method can be useful for debugging and logging (e.g. if the server
907+
* responded with an unexpected value).
908+
*/
909+
@JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type
910+
911+
/**
912+
* Returns the raw JSON value of [text].
913+
*
914+
* Unlike [text], this method doesn't throw if the JSON field has an unexpected type.
915+
*/
916+
@JsonProperty("text") @ExcludeMissing fun _text(): JsonField<String> = text
917+
918+
@JsonAnySetter
919+
private fun putAdditionalProperty(key: String, value: JsonValue) {
920+
additionalProperties.put(key, value)
921+
}
922+
923+
@JsonAnyGetter
924+
@ExcludeMissing
925+
fun _additionalProperties(): Map<String, JsonValue> =
926+
Collections.unmodifiableMap(additionalProperties)
927+
928+
fun toBuilder() = Builder().from(this)
929+
930+
companion object {
931+
932+
/**
933+
* Returns a mutable builder for constructing an instance of [ReasoningText].
934+
*
935+
* The following fields are required:
936+
* ```java
937+
* .text()
938+
* ```
939+
*/
940+
@JvmStatic fun builder() = Builder()
941+
}
942+
943+
/** A builder for [ReasoningText]. */
944+
class Builder internal constructor() {
945+
946+
private var text: JsonField<String>? = null
947+
private var type: JsonValue = JsonValue.from("reasoning_text")
948+
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
949+
950+
@JvmSynthetic
951+
internal fun from(reasoningText: ReasoningText) = apply {
952+
text = reasoningText.text
953+
type = reasoningText.type
954+
additionalProperties = reasoningText.additionalProperties.toMutableMap()
955+
}
956+
957+
/** The reasoning text from the model. */
958+
fun text(text: String) = text(JsonField.of(text))
959+
960+
/**
961+
* Sets [Builder.text] to an arbitrary JSON value.
962+
*
963+
* You should usually call [Builder.text] with a well-typed [String] value instead.
964+
* This method is primarily for setting the field to an undocumented or not yet
965+
* supported value.
966+
*/
967+
fun text(text: JsonField<String>) = apply { this.text = text }
968+
969+
/**
970+
* Sets the field to an arbitrary JSON value.
971+
*
972+
* It is usually unnecessary to call this method because the field defaults to the
973+
* following:
974+
* ```java
975+
* JsonValue.from("reasoning_text")
976+
* ```
977+
*
978+
* This method is primarily for setting the field to an undocumented or not yet
979+
* supported value.
980+
*/
981+
fun type(type: JsonValue) = apply { this.type = type }
982+
983+
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
984+
this.additionalProperties.clear()
985+
putAllAdditionalProperties(additionalProperties)
986+
}
987+
988+
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
989+
additionalProperties.put(key, value)
990+
}
991+
992+
fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
993+
apply {
994+
this.additionalProperties.putAll(additionalProperties)
995+
}
996+
997+
fun removeAdditionalProperty(key: String) = apply {
998+
additionalProperties.remove(key)
999+
}
1000+
1001+
fun removeAllAdditionalProperties(keys: Set<String>) = apply {
1002+
keys.forEach(::removeAdditionalProperty)
1003+
}
1004+
1005+
/**
1006+
* Returns an immutable instance of [ReasoningText].
1007+
*
1008+
* Further updates to this [Builder] will not mutate the returned instance.
1009+
*
1010+
* The following fields are required:
1011+
* ```java
1012+
* .text()
1013+
* ```
1014+
*
1015+
* @throws IllegalStateException if any required field is unset.
1016+
*/
1017+
fun build(): ReasoningText =
1018+
ReasoningText(
1019+
checkRequired("text", text),
1020+
type,
1021+
additionalProperties.toMutableMap(),
1022+
)
1023+
}
1024+
1025+
private var validated: Boolean = false
1026+
1027+
fun validate(): ReasoningText = apply {
1028+
if (validated) {
1029+
return@apply
1030+
}
1031+
1032+
text()
1033+
_type().let {
1034+
if (it != JsonValue.from("reasoning_text")) {
1035+
throw OpenAIInvalidDataException("'type' is invalid, received $it")
1036+
}
1037+
}
1038+
validated = true
1039+
}
1040+
1041+
fun isValid(): Boolean =
1042+
try {
1043+
validate()
1044+
true
1045+
} catch (e: OpenAIInvalidDataException) {
1046+
false
1047+
}
1048+
1049+
/**
1050+
* Returns a score indicating how many valid values are contained in this object
1051+
* recursively.
1052+
*
1053+
* Used for best match union deserialization.
1054+
*/
1055+
@JvmSynthetic
1056+
internal fun validity(): Int =
1057+
(if (text.asKnown().isPresent) 1 else 0) +
1058+
type.let { if (it == JsonValue.from("reasoning_text")) 1 else 0 }
1059+
1060+
override fun equals(other: Any?): Boolean {
1061+
if (this === other) {
1062+
return true
1063+
}
1064+
1065+
return other is ReasoningText &&
1066+
text == other.text &&
1067+
type == other.type &&
1068+
additionalProperties == other.additionalProperties
1069+
}
1070+
1071+
private val hashCode: Int by lazy { Objects.hash(text, type, additionalProperties) }
1072+
1073+
override fun hashCode(): Int = hashCode
1074+
1075+
override fun toString() =
1076+
"ReasoningText{text=$text, type=$type, additionalProperties=$additionalProperties}"
1077+
}
8251078
}
8261079

8271080
/**

openai-java-core/src/main/kotlin/com/openai/models/conversations/SummaryTextContent.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ private constructor(
3030
) : this(text, type, mutableMapOf())
3131

3232
/**
33+
* A summary of the reasoning output from the model so far.
34+
*
3335
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
3436
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
3537
*/
3638
fun text(): String = text.getRequired("text")
3739

3840
/**
41+
* The type of the object. Always `summary_text`.
42+
*
3943
* Expected to always return the following:
4044
* ```java
4145
* JsonValue.from("summary_text")
@@ -92,6 +96,7 @@ private constructor(
9296
additionalProperties = summaryTextContent.additionalProperties.toMutableMap()
9397
}
9498

99+
/** A summary of the reasoning output from the model so far. */
95100
fun text(text: String) = text(JsonField.of(text))
96101

97102
/**

0 commit comments

Comments
 (0)