diff --git a/.release-please-manifest.json b/.release-please-manifest.json index f6592787d..ea2682c30 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.40.1" + ".": "0.41.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b534119d3..2c7831dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 0.41.0 (2025-03-31) + +Full Changelog: [v0.40.1...v0.41.0](https://github.com/openai/openai-java/compare/v0.40.1...v0.41.0) + +### Features + +* **client:** improve some method names ([#379](https://github.com/openai/openai-java/issues/379)) ([895f99a](https://github.com/openai/openai-java/commit/895f99acaee6f8e38165c72da1de18e3d7682321)) + + +### Bug Fixes + +* **client:** limit json deserialization coercion ([#377](https://github.com/openai/openai-java/issues/377)) ([5234cf9](https://github.com/openai/openai-java/commit/5234cf94a540191ae051e3123b7d1be088655100)) + ## 0.40.1 (2025-03-28) Full Changelog: [v0.40.0...v0.40.1](https://github.com/openai/openai-java/compare/v0.40.0...v0.40.1) diff --git a/README.md b/README.md index ade6cb39e..2d63def00 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.40.1) -[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.40.1/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.40.1) +[![Maven Central](https://img.shields.io/maven-central/v/com.openai/openai-java)](https://central.sonatype.com/artifact/com.openai/openai-java/0.41.0) +[![javadoc](https://javadoc.io/badge2/com.openai/openai-java/0.41.0/javadoc.svg)](https://javadoc.io/doc/com.openai/openai-java/0.41.0) @@ -18,7 +18,7 @@ The OpenAI Java SDK provides convenient access to the [OpenAI REST API](https:// -The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/0.40.1). +The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs). Javadocs are also available on [javadoc.io](https://javadoc.io/doc/com.openai/openai-java/0.41.0). @@ -29,7 +29,7 @@ The REST API documentation can be found on [platform.openai.com](https://platfor ### Gradle ```kotlin -implementation("com.openai:openai-java:0.40.1") +implementation("com.openai:openai-java:0.41.0") ``` ### Maven @@ -38,7 +38,7 @@ implementation("com.openai:openai-java:0.40.1") com.openai openai-java - 0.40.1 + 0.41.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 55640a982..8a43575cd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.openai" - version = "0.40.1" // x-release-please-version + version = "0.41.0" // x-release-please-version } subprojects { diff --git a/openai-java-core/build.gradle.kts b/openai-java-core/build.gradle.kts index 6e3bd4a36..91a5af654 100644 --- a/openai-java-core/build.gradle.kts +++ b/openai-java-core/build.gradle.kts @@ -34,6 +34,7 @@ dependencies { testImplementation("org.assertj:assertj-core:3.25.3") testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3") + testImplementation("org.junit-pioneer:junit-pioneer:1.9.1") testImplementation("org.mockito:mockito-core:5.14.2") testImplementation("org.mockito:mockito-junit-jupiter:5.14.2") testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") diff --git a/openai-java-core/src/main/kotlin/com/openai/core/ObjectMappers.kt b/openai-java-core/src/main/kotlin/com/openai/core/ObjectMappers.kt index f5692c880..7be25df3f 100644 --- a/openai-java-core/src/main/kotlin/com/openai/core/ObjectMappers.kt +++ b/openai-java-core/src/main/kotlin/com/openai/core/ObjectMappers.kt @@ -8,8 +8,11 @@ import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.MapperFeature import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.cfg.CoercionAction +import com.fasterxml.jackson.databind.cfg.CoercionInputShape import com.fasterxml.jackson.databind.json.JsonMapper import com.fasterxml.jackson.databind.module.SimpleModule +import com.fasterxml.jackson.databind.type.LogicalType import com.fasterxml.jackson.datatype.jdk8.Jdk8Module import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.kotlin.kotlinModule @@ -21,6 +24,60 @@ fun jsonMapper(): JsonMapper = .addModule(Jdk8Module()) .addModule(JavaTimeModule()) .addModule(SimpleModule().addSerializer(InputStreamJsonSerializer)) + .withCoercionConfig(LogicalType.Boolean) { + it.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Integer) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Float) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Textual) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Array) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Collection) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.Map) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } + .withCoercionConfig(LogicalType.POJO) { + it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.String, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + } .serializationInclusion(JsonInclude.Include.NON_ABSENT) .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) .disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/Assistant.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/Assistant.kt index eb609d171..d6ef22949 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/Assistant.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/Assistant.kt @@ -601,10 +601,8 @@ private constructor( this.responseFormat = responseFormat } - /** - * Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = responseFormat(AssistantResponseFormatOption.ofJsonValue()) + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = responseFormat(AssistantResponseFormatOption.ofAuto()) /** * Alias for calling [responseFormat] with diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantCreateParams.kt index bc98117c5..4d7cda26e 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantCreateParams.kt @@ -446,10 +446,8 @@ private constructor( body.responseFormat(responseFormat) } - /** - * Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = apply { body.responseFormatJsonValue() } + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = apply { body.responseFormatAuto() } /** * Alias for calling [responseFormat] with @@ -1247,12 +1245,8 @@ private constructor( this.responseFormat = responseFormat } - /** - * Alias for calling [responseFormat] with - * `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = - responseFormat(AssistantResponseFormatOption.ofJsonValue()) + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = responseFormat(AssistantResponseFormatOption.ofAuto()) /** * Alias for calling [responseFormat] with diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantUpdateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantUpdateParams.kt index 757326714..2d3bfcbec 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantUpdateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/assistants/AssistantUpdateParams.kt @@ -443,10 +443,8 @@ private constructor( body.responseFormat(responseFormat) } - /** - * Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = apply { body.responseFormatJsonValue() } + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = apply { body.responseFormatAuto() } /** * Alias for calling [responseFormat] with @@ -1244,12 +1242,8 @@ private constructor( this.responseFormat = responseFormat } - /** - * Alias for calling [responseFormat] with - * `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = - responseFormat(AssistantResponseFormatOption.ofJsonValue()) + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = responseFormat(AssistantResponseFormatOption.ofAuto()) /** * Alias for calling [responseFormat] with diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOption.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOption.kt index 216b63c9c..31b3815db 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOption.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOption.kt @@ -44,7 +44,7 @@ import java.util.Optional @JsonSerialize(using = AssistantResponseFormatOption.Serializer::class) class AssistantResponseFormatOption private constructor( - private val jsonValue: JsonValue? = null, + private val auto: JsonValue? = null, private val responseFormatText: ResponseFormatText? = null, private val responseFormatJsonObject: ResponseFormatJsonObject? = null, private val responseFormatJsonSchema: ResponseFormatJsonSchema? = null, @@ -52,7 +52,7 @@ private constructor( ) { /** `auto` is the default value */ - fun jsonValue(): Optional = Optional.ofNullable(jsonValue) + fun auto(): Optional = Optional.ofNullable(auto) /** Default response format. Used to generate text responses. */ fun responseFormatText(): Optional = Optional.ofNullable(responseFormatText) @@ -72,7 +72,7 @@ private constructor( fun responseFormatJsonSchema(): Optional = Optional.ofNullable(responseFormatJsonSchema) - fun isJsonValue(): Boolean = jsonValue != null + fun isAuto(): Boolean = auto != null fun isResponseFormatText(): Boolean = responseFormatText != null @@ -81,7 +81,7 @@ private constructor( fun isResponseFormatJsonSchema(): Boolean = responseFormatJsonSchema != null /** `auto` is the default value */ - fun asJsonValue(): JsonValue = jsonValue.getOrThrow("jsonValue") + fun asAuto(): JsonValue = auto.getOrThrow("auto") /** Default response format. Used to generate text responses. */ fun asResponseFormatText(): ResponseFormatText = @@ -106,7 +106,7 @@ private constructor( fun accept(visitor: Visitor): T { return when { - jsonValue != null -> visitor.visitJsonValue(jsonValue) + auto != null -> visitor.visitAuto(auto) responseFormatText != null -> visitor.visitResponseFormatText(responseFormatText) responseFormatJsonObject != null -> visitor.visitResponseFormatJsonObject(responseFormatJsonObject) @@ -125,10 +125,10 @@ private constructor( accept( object : Visitor { - override fun visitJsonValue(jsonValue: JsonValue) { - jsonValue.let { + override fun visitAuto(auto: JsonValue) { + auto.let { if (it != JsonValue.from("auto")) { - throw OpenAIInvalidDataException("'jsonValue' is invalid, received $it") + throw OpenAIInvalidDataException("'auto' is invalid, received $it") } } } @@ -158,14 +158,14 @@ private constructor( return true } - return /* spotless:off */ other is AssistantResponseFormatOption && jsonValue == other.jsonValue && responseFormatText == other.responseFormatText && responseFormatJsonObject == other.responseFormatJsonObject && responseFormatJsonSchema == other.responseFormatJsonSchema /* spotless:on */ + return /* spotless:off */ other is AssistantResponseFormatOption && auto == other.auto && responseFormatText == other.responseFormatText && responseFormatJsonObject == other.responseFormatJsonObject && responseFormatJsonSchema == other.responseFormatJsonSchema /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(jsonValue, responseFormatText, responseFormatJsonObject, responseFormatJsonSchema) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(auto, responseFormatText, responseFormatJsonObject, responseFormatJsonSchema) /* spotless:on */ override fun toString(): String = when { - jsonValue != null -> "AssistantResponseFormatOption{jsonValue=$jsonValue}" + auto != null -> "AssistantResponseFormatOption{auto=$auto}" responseFormatText != null -> "AssistantResponseFormatOption{responseFormatText=$responseFormatText}" responseFormatJsonObject != null -> @@ -179,8 +179,7 @@ private constructor( companion object { /** `auto` is the default value */ - @JvmStatic - fun ofJsonValue() = AssistantResponseFormatOption(jsonValue = JsonValue.from("auto")) + @JvmStatic fun ofAuto() = AssistantResponseFormatOption(auto = JsonValue.from("auto")) /** Default response format. Used to generate text responses. */ @JvmStatic @@ -212,7 +211,7 @@ private constructor( interface Visitor { /** `auto` is the default value */ - fun visitJsonValue(jsonValue: JsonValue): T + fun visitAuto(auto: JsonValue): T /** Default response format. Used to generate text responses. */ fun visitResponseFormatText(responseFormatText: ResponseFormatText): T @@ -254,12 +253,12 @@ private constructor( tryDeserialize(node, jacksonTypeRef()) { it.let { if (it != JsonValue.from("auto")) { - throw OpenAIInvalidDataException("'jsonValue' is invalid, received $it") + throw OpenAIInvalidDataException("'auto' is invalid, received $it") } } } ?.let { - return AssistantResponseFormatOption(jsonValue = it, _json = json) + return AssistantResponseFormatOption(auto = it, _json = json) } tryDeserialize(node, jacksonTypeRef()) { it.validate() } ?.let { @@ -293,7 +292,7 @@ private constructor( provider: SerializerProvider, ) { when { - value.jsonValue != null -> generator.writeObject(value.jsonValue) + value.auto != null -> generator.writeObject(value.auto) value.responseFormatText != null -> generator.writeObject(value.responseFormatText) value.responseFormatJsonObject != null -> generator.writeObject(value.responseFormatJsonObject) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/ThreadCreateAndRunParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/ThreadCreateAndRunParams.kt index ace05e4c5..84ddab3ba 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/ThreadCreateAndRunParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/ThreadCreateAndRunParams.kt @@ -570,10 +570,8 @@ private constructor( body.responseFormat(responseFormat) } - /** - * Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = apply { body.responseFormatJsonValue() } + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = apply { body.responseFormatAuto() } /** * Alias for calling [responseFormat] with @@ -1599,12 +1597,8 @@ private constructor( this.responseFormat = responseFormat } - /** - * Alias for calling [responseFormat] with - * `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = - responseFormat(AssistantResponseFormatOption.ofJsonValue()) + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = responseFormat(AssistantResponseFormatOption.ofAuto()) /** * Alias for calling [responseFormat] with diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/Message.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/Message.kt index 35ebb5978..d0b1aacf9 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/Message.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/messages/Message.kt @@ -926,9 +926,8 @@ private constructor( fun addTool(codeInterpreter: CodeInterpreterTool) = addTool(Tool.ofCodeInterpreter(codeInterpreter)) - /** Alias for calling [addTool] with `Tool.ofAssistantToolsFileSearchTypeOnly()`. */ - fun addToolAssistantToolsFileSearchTypeOnly() = - addTool(Tool.ofAssistantToolsFileSearchTypeOnly()) + /** Alias for calling [addTool] with `Tool.ofObject()`. */ + fun addToolObject() = addTool(Tool.ofObject()) fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -979,36 +978,30 @@ private constructor( class Tool private constructor( private val codeInterpreter: CodeInterpreterTool? = null, - private val assistantToolsFileSearchTypeOnly: JsonValue? = null, + private val object_: JsonValue? = null, private val _json: JsonValue? = null, ) { fun codeInterpreter(): Optional = Optional.ofNullable(codeInterpreter) - fun assistantToolsFileSearchTypeOnly(): Optional = - Optional.ofNullable(assistantToolsFileSearchTypeOnly) + fun object_(): Optional = Optional.ofNullable(object_) fun isCodeInterpreter(): Boolean = codeInterpreter != null - fun isAssistantToolsFileSearchTypeOnly(): Boolean = - assistantToolsFileSearchTypeOnly != null + fun isObject(): Boolean = object_ != null fun asCodeInterpreter(): CodeInterpreterTool = codeInterpreter.getOrThrow("codeInterpreter") - fun asAssistantToolsFileSearchTypeOnly(): JsonValue = - assistantToolsFileSearchTypeOnly.getOrThrow("assistantToolsFileSearchTypeOnly") + fun asObject(): JsonValue = object_.getOrThrow("object_") fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T { return when { codeInterpreter != null -> visitor.visitCodeInterpreter(codeInterpreter) - assistantToolsFileSearchTypeOnly != null -> - visitor.visitAssistantToolsFileSearchTypeOnly( - assistantToolsFileSearchTypeOnly - ) + object_ != null -> visitor.visitObject(object_) else -> visitor.unknown(_json) } } @@ -1026,13 +1019,11 @@ private constructor( codeInterpreter.validate() } - override fun visitAssistantToolsFileSearchTypeOnly( - assistantToolsFileSearchTypeOnly: JsonValue - ) { - assistantToolsFileSearchTypeOnly.let { + override fun visitObject(object_: JsonValue) { + object_.let { if (it != JsonValue.from(mapOf("type" to "file_search"))) { throw OpenAIInvalidDataException( - "'assistantToolsFileSearchTypeOnly' is invalid, received $it" + "'object_' is invalid, received $it" ) } } @@ -1047,16 +1038,15 @@ private constructor( return true } - return /* spotless:off */ other is Tool && codeInterpreter == other.codeInterpreter && assistantToolsFileSearchTypeOnly == other.assistantToolsFileSearchTypeOnly /* spotless:on */ + return /* spotless:off */ other is Tool && codeInterpreter == other.codeInterpreter && object_ == other.object_ /* spotless:on */ } - override fun hashCode(): Int = /* spotless:off */ Objects.hash(codeInterpreter, assistantToolsFileSearchTypeOnly) /* spotless:on */ + override fun hashCode(): Int = /* spotless:off */ Objects.hash(codeInterpreter, object_) /* spotless:on */ override fun toString(): String = when { codeInterpreter != null -> "Tool{codeInterpreter=$codeInterpreter}" - assistantToolsFileSearchTypeOnly != null -> - "Tool{assistantToolsFileSearchTypeOnly=$assistantToolsFileSearchTypeOnly}" + object_ != null -> "Tool{object_=$object_}" _json != null -> "Tool{_unknown=$_json}" else -> throw IllegalStateException("Invalid Tool") } @@ -1068,11 +1058,7 @@ private constructor( Tool(codeInterpreter = codeInterpreter) @JvmStatic - fun ofAssistantToolsFileSearchTypeOnly() = - Tool( - assistantToolsFileSearchTypeOnly = - JsonValue.from(mapOf("type" to "file_search")) - ) + fun ofObject() = Tool(object_ = JsonValue.from(mapOf("type" to "file_search"))) } /** @@ -1082,9 +1068,7 @@ private constructor( fun visitCodeInterpreter(codeInterpreter: CodeInterpreterTool): T - fun visitAssistantToolsFileSearchTypeOnly( - assistantToolsFileSearchTypeOnly: JsonValue - ): T + fun visitObject(object_: JsonValue): T /** * Maps an unknown variant of [Tool] to a value of type [T]. @@ -1114,13 +1098,13 @@ private constructor( it.let { if (it != JsonValue.from(mapOf("type" to "file_search"))) { throw OpenAIInvalidDataException( - "'assistantToolsFileSearchTypeOnly' is invalid, received $it" + "'object_' is invalid, received $it" ) } } } ?.let { - return Tool(assistantToolsFileSearchTypeOnly = it, _json = json) + return Tool(object_ = it, _json = json) } return Tool(_json = json) @@ -1137,8 +1121,7 @@ private constructor( when { value.codeInterpreter != null -> generator.writeObject(value.codeInterpreter) - value.assistantToolsFileSearchTypeOnly != null -> - generator.writeObject(value.assistantToolsFileSearchTypeOnly) + value.object_ != null -> generator.writeObject(value.object_) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Tool") } diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/Run.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/Run.kt index cbd118356..54ad02d92 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/Run.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/Run.kt @@ -1106,10 +1106,8 @@ private constructor( this.responseFormat = responseFormat } - /** - * Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = responseFormat(AssistantResponseFormatOption.ofJsonValue()) + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = responseFormat(AssistantResponseFormatOption.ofAuto()) /** * Alias for calling [responseFormat] with diff --git a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunCreateParams.kt b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunCreateParams.kt index 9c6c8887e..3bc7817ba 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunCreateParams.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/beta/threads/runs/RunCreateParams.kt @@ -731,10 +731,8 @@ private constructor( body.responseFormat(responseFormat) } - /** - * Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = apply { body.responseFormatJsonValue() } + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = apply { body.responseFormatAuto() } /** * Alias for calling [responseFormat] with @@ -1873,12 +1871,8 @@ private constructor( this.responseFormat = responseFormat } - /** - * Alias for calling [responseFormat] with - * `AssistantResponseFormatOption.ofJsonValue()`. - */ - fun responseFormatJsonValue() = - responseFormat(AssistantResponseFormatOption.ofJsonValue()) + /** Alias for calling [responseFormat] with `AssistantResponseFormatOption.ofAuto()`. */ + fun responseFormatAuto() = responseFormat(AssistantResponseFormatOption.ofAuto()) /** * Alias for calling [responseFormat] with diff --git a/openai-java-core/src/test/kotlin/com/openai/core/ObjectMappersTest.kt b/openai-java-core/src/test/kotlin/com/openai/core/ObjectMappersTest.kt new file mode 100644 index 000000000..17fe45c36 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/core/ObjectMappersTest.kt @@ -0,0 +1,81 @@ +package com.openai.core + +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.exc.MismatchedInputException +import kotlin.reflect.KClass +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.catchThrowable +import org.junit.jupiter.api.Test +import org.junitpioneer.jupiter.cartesian.CartesianTest + +internal class ObjectMappersTest { + + internal class ClassWithBooleanFieldPrefixedWithIs(private val isActive: JsonField) { + + @JsonProperty("is_active") @ExcludeMissing fun _isActive() = isActive + } + + @Test + fun write_whenFieldPrefixedWithIs_keepsPrefix() { + val value = ClassWithBooleanFieldPrefixedWithIs(JsonField.of(true)) + + val json = jsonMapper().writeValueAsString(value) + + assertThat(json).isEqualTo("{\"is_active\":true}") + } + + internal class Class(@get:JsonProperty("field") @JsonProperty("field") val field: String) + + enum class ShapeTestCase(val value: Any, val kClass: KClass<*>) { + STRING("Hello World!", String::class), + BOOLEAN(true, Boolean::class), + FLOAT(3.14F, Float::class), + DOUBLE(3.14, Double::class), + INTEGER(42, Int::class), + LONG(42L, Long::class), + MAP(mapOf("property" to "value"), Map::class), + CLASS(Class("Hello World!"), Class::class), + LIST(listOf(1, 2, 3), List::class); + + companion object { + val VALID_CONVERSIONS = + listOf( + FLOAT to DOUBLE, + FLOAT to INTEGER, + FLOAT to LONG, + DOUBLE to FLOAT, + DOUBLE to INTEGER, + DOUBLE to LONG, + INTEGER to FLOAT, + INTEGER to DOUBLE, + INTEGER to LONG, + LONG to FLOAT, + LONG to DOUBLE, + LONG to INTEGER, + CLASS to MAP, + // These aren't actually valid, but coercion configs don't work for String until + // v2.14.0: https://github.com/FasterXML/jackson-databind/issues/3240 + // We currently test on v2.13.4. + BOOLEAN to STRING, + FLOAT to STRING, + DOUBLE to STRING, + INTEGER to STRING, + LONG to STRING, + ) + } + } + + @CartesianTest + fun read(@CartesianTest.Enum shape1: ShapeTestCase, @CartesianTest.Enum shape2: ShapeTestCase) { + val jsonMapper = jsonMapper() + val json = jsonMapper.writeValueAsString(shape1.value) + + val e = catchThrowable { jsonMapper.readValue(json, shape2.kClass.java) } + + if (shape1 == shape2 || shape1 to shape2 in ShapeTestCase.VALID_CONVERSIONS) { + assertThat(e).isNull() + } else { + assertThat(e).isInstanceOf(MismatchedInputException::class.java) + } + } +} diff --git a/openai-java-core/src/test/kotlin/com/openai/core/http/SerializerTest.kt b/openai-java-core/src/test/kotlin/com/openai/core/http/SerializerTest.kt deleted file mode 100644 index f0a3d482a..000000000 --- a/openai-java-core/src/test/kotlin/com/openai/core/http/SerializerTest.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.openai.core.http - -import com.fasterxml.jackson.annotation.JsonAnyGetter -import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.openai.core.* -import java.util.* -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class SerializerTest { - @JsonDeserialize(builder = ClassWithBooleanFieldPrefixedWithIs.Builder::class) - class ClassWithBooleanFieldPrefixedWithIs - private constructor( - private val isActive: JsonField, - private val additionalProperties: Map, - ) { - private var validated: Boolean = false - - private var hashCode: Int = 0 - - fun isActive(): Boolean? = isActive.getNullable("is_active") - - @JsonProperty("is_active") @ExcludeMissing fun _isActive() = isActive - - @JsonAnyGetter - @ExcludeMissing - fun _additionalProperties(): Map = additionalProperties - - fun validate() = apply { - if (!validated) { - isActive() - validated = true - } - } - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return other is ClassWithBooleanFieldPrefixedWithIs && - isActive == other.isActive && - additionalProperties == other.additionalProperties - } - - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = Objects.hash(isActive, additionalProperties) - } - return hashCode - } - - override fun toString() = - "MyClass{isActive=$isActive, additionalProperties=$additionalProperties}" - - companion object { - fun builder() = Builder() - } - - class Builder internal constructor() { - - private var isActive: JsonField = JsonMissing.of() - private var additionalProperties: MutableMap = mutableMapOf() - - fun isActive(isActive: Boolean) = isActive(JsonField.of(isActive)) - - @JsonProperty("is_active") - @ExcludeMissing - fun isActive(isActive: JsonField) = apply { this.isActive = isActive } - - fun additionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) - } - - @JsonAnySetter - fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) - } - - fun putAllAdditionalProperties(additionalProperties: Map) = apply { - this.additionalProperties.putAll(additionalProperties) - } - - fun build(): ClassWithBooleanFieldPrefixedWithIs = - ClassWithBooleanFieldPrefixedWithIs(isActive, additionalProperties.toImmutable()) - } - } - - @Test - fun serializeBooleanPrefixedWithIs() { - val value = ClassWithBooleanFieldPrefixedWithIs.builder().isActive(true).build() - assertThat(jsonMapper().writeValueAsString(value)).isEqualTo("{\"is_active\":true}") - } -} diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantCreateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantCreateParamsTest.kt index 2dd8be917..1f60f0ee7 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantCreateParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantCreateParamsTest.kt @@ -25,7 +25,7 @@ internal class AssistantCreateParamsTest { ) .name("name") .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( AssistantCreateParams.ToolResources.builder() @@ -73,7 +73,7 @@ internal class AssistantCreateParamsTest { ) .name("name") .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( AssistantCreateParams.ToolResources.builder() @@ -124,7 +124,7 @@ internal class AssistantCreateParamsTest { ) assertThat(body.name()).contains("name") assertThat(body.reasoningEffort()).contains(ReasoningEffort.LOW) - assertThat(body.responseFormat()).contains(AssistantResponseFormatOption.ofJsonValue()) + assertThat(body.responseFormat()).contains(AssistantResponseFormatOption.ofAuto()) assertThat(body.temperature()).contains(1.0) assertThat(body.toolResources()) .contains( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantStreamEventTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantStreamEventTest.kt index ebdb98c60..a1e1c5331 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantStreamEventTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantStreamEventTest.kt @@ -118,7 +118,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -218,7 +218,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -318,7 +318,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -418,7 +418,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -519,7 +519,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -619,7 +619,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -719,7 +719,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -819,7 +819,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -919,7 +919,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -1019,7 +1019,7 @@ internal class AssistantStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantTest.kt index 04c2b24ac..adfad5e46 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantTest.kt @@ -25,7 +25,7 @@ internal class AssistantTest { .model("model") .name("name") .addTool(CodeInterpreterTool.builder().build()) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( Assistant.ToolResources.builder() @@ -58,7 +58,7 @@ internal class AssistantTest { assertThat(assistant.name()).contains("name") assertThat(assistant.tools()) .containsExactly(AssistantTool.ofCodeInterpreter(CodeInterpreterTool.builder().build())) - assertThat(assistant.responseFormat()).contains(AssistantResponseFormatOption.ofJsonValue()) + assertThat(assistant.responseFormat()).contains(AssistantResponseFormatOption.ofAuto()) assertThat(assistant.temperature()).contains(1.0) assertThat(assistant.toolResources()) .contains( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantUpdateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantUpdateParamsTest.kt index 6895a0009..d9eb3d3b4 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantUpdateParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/AssistantUpdateParamsTest.kt @@ -25,7 +25,7 @@ internal class AssistantUpdateParamsTest { .model(AssistantUpdateParams.Model.O3_MINI) .name("name") .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( AssistantUpdateParams.ToolResources.builder() @@ -70,7 +70,7 @@ internal class AssistantUpdateParamsTest { .model(AssistantUpdateParams.Model.O3_MINI) .name("name") .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( AssistantUpdateParams.ToolResources.builder() @@ -103,7 +103,7 @@ internal class AssistantUpdateParamsTest { assertThat(body.model()).contains(AssistantUpdateParams.Model.O3_MINI) assertThat(body.name()).contains("name") assertThat(body.reasoningEffort()).contains(ReasoningEffort.LOW) - assertThat(body.responseFormat()).contains(AssistantResponseFormatOption.ofJsonValue()) + assertThat(body.responseFormat()).contains(AssistantResponseFormatOption.ofAuto()) assertThat(body.temperature()).contains(1.0) assertThat(body.toolResources()) .contains( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/RunStreamEventTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/RunStreamEventTest.kt index 97b04deae..d6d7e9651 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/RunStreamEventTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/assistants/RunStreamEventTest.kt @@ -62,7 +62,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -148,7 +148,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -234,7 +234,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -320,7 +320,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -406,7 +406,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -492,7 +492,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -578,7 +578,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -664,7 +664,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -750,7 +750,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -836,7 +836,7 @@ internal class RunStreamEventTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOptionTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOptionTest.kt index 52acf80d6..666790a41 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOptionTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/AssistantResponseFormatOptionTest.kt @@ -12,10 +12,10 @@ import org.junit.jupiter.api.Test internal class AssistantResponseFormatOptionTest { @Test - fun ofJsonValue() { - val assistantResponseFormatOption = AssistantResponseFormatOption.ofJsonValue() + fun ofAuto() { + val assistantResponseFormatOption = AssistantResponseFormatOption.ofAuto() - assertThat(assistantResponseFormatOption.jsonValue()).contains(JsonValue.from("auto")) + assertThat(assistantResponseFormatOption.auto()).contains(JsonValue.from("auto")) assertThat(assistantResponseFormatOption.responseFormatText()).isEmpty assertThat(assistantResponseFormatOption.responseFormatJsonObject()).isEmpty assertThat(assistantResponseFormatOption.responseFormatJsonSchema()).isEmpty @@ -28,7 +28,7 @@ internal class AssistantResponseFormatOptionTest { val assistantResponseFormatOption = AssistantResponseFormatOption.ofResponseFormatText(responseFormatText) - assertThat(assistantResponseFormatOption.jsonValue()).isEmpty + assertThat(assistantResponseFormatOption.auto()).isEmpty assertThat(assistantResponseFormatOption.responseFormatText()).contains(responseFormatText) assertThat(assistantResponseFormatOption.responseFormatJsonObject()).isEmpty assertThat(assistantResponseFormatOption.responseFormatJsonSchema()).isEmpty @@ -41,7 +41,7 @@ internal class AssistantResponseFormatOptionTest { val assistantResponseFormatOption = AssistantResponseFormatOption.ofResponseFormatJsonObject(responseFormatJsonObject) - assertThat(assistantResponseFormatOption.jsonValue()).isEmpty + assertThat(assistantResponseFormatOption.auto()).isEmpty assertThat(assistantResponseFormatOption.responseFormatText()).isEmpty assertThat(assistantResponseFormatOption.responseFormatJsonObject()) .contains(responseFormatJsonObject) @@ -58,7 +58,7 @@ internal class AssistantResponseFormatOptionTest { val assistantResponseFormatOption = AssistantResponseFormatOption.ofResponseFormatJsonSchema(responseFormatJsonSchema) - assertThat(assistantResponseFormatOption.jsonValue()).isEmpty + assertThat(assistantResponseFormatOption.auto()).isEmpty assertThat(assistantResponseFormatOption.responseFormatText()).isEmpty assertThat(assistantResponseFormatOption.responseFormatJsonObject()).isEmpty assertThat(assistantResponseFormatOption.responseFormatJsonSchema()) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/ThreadCreateAndRunParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/ThreadCreateAndRunParamsTest.kt index ff52cd6a8..84afd0efb 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/ThreadCreateAndRunParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/ThreadCreateAndRunParamsTest.kt @@ -25,7 +25,7 @@ internal class ThreadCreateAndRunParamsTest { ) .model(ChatModel.O3_MINI) .parallelToolCalls(true) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .thread( ThreadCreateAndRunParams.Thread.builder() @@ -129,7 +129,7 @@ internal class ThreadCreateAndRunParamsTest { ) .model(ChatModel.O3_MINI) .parallelToolCalls(true) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .thread( ThreadCreateAndRunParams.Thread.builder() @@ -232,7 +232,7 @@ internal class ThreadCreateAndRunParamsTest { ) assertThat(body.model()).contains(ChatModel.O3_MINI) assertThat(body.parallelToolCalls()).contains(true) - assertThat(body.responseFormat()).contains(AssistantResponseFormatOption.ofJsonValue()) + assertThat(body.responseFormat()).contains(AssistantResponseFormatOption.ofAuto()) assertThat(body.temperature()).contains(1.0) assertThat(body.thread()) .contains( diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunCreateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunCreateParamsTest.kt index 40cee3454..19e937383 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunCreateParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunCreateParamsTest.kt @@ -52,7 +52,7 @@ internal class RunCreateParamsTest { .model(ChatModel.O3_MINI) .parallelToolCalls(true) .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolChoice(AssistantToolChoiceOption.Auto.NONE) .addTool(CodeInterpreterTool.builder().build()) @@ -112,7 +112,7 @@ internal class RunCreateParamsTest { .model(ChatModel.O3_MINI) .parallelToolCalls(true) .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolChoice(AssistantToolChoiceOption.Auto.NONE) .addTool(CodeInterpreterTool.builder().build()) @@ -181,7 +181,7 @@ internal class RunCreateParamsTest { .model(ChatModel.O3_MINI) .parallelToolCalls(true) .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolChoice(AssistantToolChoiceOption.Auto.NONE) .addTool(CodeInterpreterTool.builder().build()) @@ -228,7 +228,7 @@ internal class RunCreateParamsTest { assertThat(body.model()).contains(ChatModel.O3_MINI) assertThat(body.parallelToolCalls()).contains(true) assertThat(body.reasoningEffort()).contains(ReasoningEffort.LOW) - assertThat(body.responseFormat()).contains(AssistantResponseFormatOption.ofJsonValue()) + assertThat(body.responseFormat()).contains(AssistantResponseFormatOption.ofAuto()) assertThat(body.temperature()).contains(1.0) assertThat(body.toolChoice()) .contains(AssistantToolChoiceOption.ofAuto(AssistantToolChoiceOption.Auto.NONE)) diff --git a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunTest.kt index 1f899c18a..d3cd81455 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/beta/threads/runs/RunTest.kt @@ -63,7 +63,7 @@ internal class RunTest { ) .build() ) - .responseFormatJsonValue() + .responseFormatAuto() .startedAt(0L) .status(RunStatus.QUEUED) .threadId("thread_id") @@ -137,7 +137,7 @@ internal class RunTest { ) .build() ) - assertThat(run.responseFormat()).contains(AssistantResponseFormatOption.ofJsonValue()) + assertThat(run.responseFormat()).contains(AssistantResponseFormatOption.ofAuto()) assertThat(run.startedAt()).contains(0L) assertThat(run.status()).isEqualTo(RunStatus.QUEUED) assertThat(run.threadId()).isEqualTo("thread_id") diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/beta/AssistantServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/beta/AssistantServiceAsyncTest.kt index b0586d587..751f8c581 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/beta/AssistantServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/beta/AssistantServiceAsyncTest.kt @@ -40,7 +40,7 @@ internal class AssistantServiceAsyncTest { ) .name("name") .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( AssistantCreateParams.ToolResources.builder() @@ -124,7 +124,7 @@ internal class AssistantServiceAsyncTest { .model(AssistantUpdateParams.Model.O3_MINI) .name("name") .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( AssistantUpdateParams.ToolResources.builder() diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/beta/ThreadServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/beta/ThreadServiceAsyncTest.kt index 90da2cf2e..f28ff9acc 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/beta/ThreadServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/beta/ThreadServiceAsyncTest.kt @@ -188,7 +188,7 @@ internal class ThreadServiceAsyncTest { ) .model(ChatModel.O3_MINI) .parallelToolCalls(true) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .thread( ThreadCreateAndRunParams.Thread.builder() @@ -308,7 +308,7 @@ internal class ThreadServiceAsyncTest { ) .model(ChatModel.O3_MINI) .parallelToolCalls(true) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .thread( ThreadCreateAndRunParams.Thread.builder() diff --git a/openai-java-core/src/test/kotlin/com/openai/services/async/beta/threads/RunServiceAsyncTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/async/beta/threads/RunServiceAsyncTest.kt index 0845cad71..0bedb5797 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/async/beta/threads/RunServiceAsyncTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/async/beta/threads/RunServiceAsyncTest.kt @@ -66,7 +66,7 @@ internal class RunServiceAsyncTest { .model(ChatModel.O3_MINI) .parallelToolCalls(true) .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolChoice(AssistantToolChoiceOption.Auto.NONE) .addTool(CodeInterpreterTool.builder().build()) @@ -128,7 +128,7 @@ internal class RunServiceAsyncTest { .model(ChatModel.O3_MINI) .parallelToolCalls(true) .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolChoice(AssistantToolChoiceOption.Auto.NONE) .addTool(CodeInterpreterTool.builder().build()) diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/AssistantServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/AssistantServiceTest.kt index 5366cce3d..182c0a29e 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/AssistantServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/AssistantServiceTest.kt @@ -40,7 +40,7 @@ internal class AssistantServiceTest { ) .name("name") .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( AssistantCreateParams.ToolResources.builder() @@ -122,7 +122,7 @@ internal class AssistantServiceTest { .model(AssistantUpdateParams.Model.O3_MINI) .name("name") .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolResources( AssistantUpdateParams.ToolResources.builder() diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/ThreadServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/ThreadServiceTest.kt index 9ef58cf90..36eb99f69 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/ThreadServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/ThreadServiceTest.kt @@ -182,7 +182,7 @@ internal class ThreadServiceTest { ) .model(ChatModel.O3_MINI) .parallelToolCalls(true) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .thread( ThreadCreateAndRunParams.Thread.builder() @@ -301,7 +301,7 @@ internal class ThreadServiceTest { ) .model(ChatModel.O3_MINI) .parallelToolCalls(true) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .thread( ThreadCreateAndRunParams.Thread.builder() diff --git a/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/threads/RunServiceTest.kt b/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/threads/RunServiceTest.kt index 5fc62effd..fd12bd9f0 100644 --- a/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/threads/RunServiceTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/services/blocking/beta/threads/RunServiceTest.kt @@ -66,7 +66,7 @@ internal class RunServiceTest { .model(ChatModel.O3_MINI) .parallelToolCalls(true) .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolChoice(AssistantToolChoiceOption.Auto.NONE) .addTool(CodeInterpreterTool.builder().build()) @@ -127,7 +127,7 @@ internal class RunServiceTest { .model(ChatModel.O3_MINI) .parallelToolCalls(true) .reasoningEffort(ReasoningEffort.LOW) - .responseFormatJsonValue() + .responseFormatAuto() .temperature(1.0) .toolChoice(AssistantToolChoiceOption.Auto.NONE) .addTool(CodeInterpreterTool.builder().build())