Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>)` 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -343,6 +344,38 @@ internal class StructuredChatCompletionCreateParamsTest {
private val builderDelegator =
StructuredChatCompletionCreateParams.builder<X>().inject(mockBuilderDelegate)

@Test
fun structuredOutputsBuilder() {
class X(val s: String)

// Only interested in a few things:
// - Does the `Builder` type change when `responseFormat(Class<T>)` 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading