diff --git a/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParamsTest.kt index d4f4337f2..c560bb0ce 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParamsTest.kt @@ -464,36 +464,4 @@ internal class ChatCompletionCreateParamsTest { ) assertThat(body.model()).isEqualTo(ChatModel.GPT_5_4) } - - @Test - fun structuredOutputsBuilder() { - class X(val s: String) - - // Only interested in a few things: - // - Does the `Builder` type change when `responseFormat(Class)` is called? - // - Are values already set on the "old" `Builder` preserved in the change-over? - // - Can new values be set on the "new" `Builder` alongside the "old" values? - val params = - ChatCompletionCreateParams.builder() - .addDeveloperMessage("dev message") - .model(ChatModel.GPT_4_1) - .responseFormat(X::class.java) // Creates and return a new builder. - .addSystemMessage("sys message") - .build() - - val body = params.rawParams._body() - - assertThat(params).isInstanceOf(StructuredChatCompletionCreateParams::class.java) - assertThat(params.responseType).isEqualTo(X::class.java) - assertThat(body.messages()) - .containsExactly( - ChatCompletionMessageParam.ofDeveloper( - ChatCompletionDeveloperMessageParam.builder().content("dev message").build() - ), - ChatCompletionMessageParam.ofSystem( - ChatCompletionSystemMessageParam.builder().content("sys message").build() - ), - ) - assertThat(body.model()).isEqualTo(ChatModel.GPT_4_1) - } } diff --git a/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/StructuredChatCompletionCreateParamsTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/StructuredChatCompletionCreateParamsTest.kt index 3be034a80..6c5b99c4a 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/StructuredChatCompletionCreateParamsTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/chat/completions/StructuredChatCompletionCreateParamsTest.kt @@ -30,6 +30,7 @@ import com.openai.models.ChatModel import com.openai.models.FunctionDefinition import com.openai.models.ResponseFormatJsonSchema import java.util.Optional +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource @@ -343,6 +344,38 @@ internal class StructuredChatCompletionCreateParamsTest { private val builderDelegator = StructuredChatCompletionCreateParams.builder().inject(mockBuilderDelegate) + @Test + fun structuredOutputsBuilder() { + class X(val s: String) + + // Only interested in a few things: + // - Does the `Builder` type change when `responseFormat(Class)` is called? + // - Are values already set on the "old" `Builder` preserved in the change-over? + // - Can new values be set on the "new" `Builder` alongside the "old" values? + val params = + ChatCompletionCreateParams.builder() + .addDeveloperMessage("dev message") + .model(ChatModel.GPT_4_1) + .responseFormat(X::class.java) // Creates and return a new builder. + .addSystemMessage("sys message") + .build() + + val body = params.rawParams._body() + + assertThat(params).isInstanceOf(StructuredChatCompletionCreateParams::class.java) + assertThat(params.responseType).isEqualTo(X::class.java) + assertThat(body.messages()) + .containsExactly( + ChatCompletionMessageParam.ofDeveloper( + ChatCompletionDeveloperMessageParam.builder().content("dev message").build() + ), + ChatCompletionMessageParam.ofSystem( + ChatCompletionSystemMessageParam.builder().content("sys message").build() + ), + ) + assertThat(body.model()).isEqualTo(ChatModel.GPT_4_1) + } + @Test fun allBuilderDelegateFunctionsExistInDelegator() { // The delegator class does not implement the various `responseFormat` functions of the diff --git a/openai-java-core/src/test/kotlin/com/openai/models/embeddings/EmbeddingTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/embeddings/EmbeddingTest.kt index 43f4f6f0a..079ffeff8 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/embeddings/EmbeddingTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/embeddings/EmbeddingTest.kt @@ -17,32 +17,6 @@ internal class EmbeddingTest { assertThat(embedding.index()).isEqualTo(0L) } - @Test - fun create_setThenAdd() { - val embedding = - Embedding.builder() - .embedding(EmbeddingValue.ofFloats(listOf(1.0f, 2.0f))) - .addEmbedding(3.0f) - .index(0L) - .build() - - assertThat(embedding.embedding()).containsExactly(1.0f, 2.0f, 3.0f) - assertThat(embedding.index()).isEqualTo(0L) - } - - @Test - fun create_addThenSet() { - val embedding = - Embedding.builder() - .addEmbedding(3.0f) - .embedding(EmbeddingValue.ofFloats(listOf(1.0f, 2.0f))) - .index(0L) - .build() - - assertThat(embedding.embedding()).containsExactly(1.0f, 2.0f) - assertThat(embedding.index()).isEqualTo(0L) - } - @Test fun roundtrip() { val jsonMapper = jsonMapper() diff --git a/openai-java-core/src/test/kotlin/com/openai/models/embeddings/EmbeddingValueTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/embeddings/EmbeddingValueTest.kt index 663237712..26338236f 100644 --- a/openai-java-core/src/test/kotlin/com/openai/models/embeddings/EmbeddingValueTest.kt +++ b/openai-java-core/src/test/kotlin/com/openai/models/embeddings/EmbeddingValueTest.kt @@ -5,6 +5,32 @@ import org.junit.jupiter.api.Test internal class EmbeddingValueTest { + @Test + fun create_setThenAdd() { + val embedding = + Embedding.builder() + .embedding(EmbeddingValue.ofFloats(listOf(1.0f, 2.0f))) + .addEmbedding(3.0f) + .index(0L) + .build() + + assertThat(embedding.embedding()).containsExactly(1.0f, 2.0f, 3.0f) + assertThat(embedding.index()).isEqualTo(0L) + } + + @Test + fun create_addThenSet() { + val embedding = + Embedding.builder() + .addEmbedding(3.0f) + .embedding(EmbeddingValue.ofFloats(listOf(1.0f, 2.0f))) + .index(0L) + .build() + + assertThat(embedding.embedding()).containsExactly(1.0f, 2.0f) + assertThat(embedding.index()).isEqualTo(0L) + } + @Test fun ofFloats() { val floats = listOf(1.0f, 2.0f, 3.0f, 4.0f)