Skip to content

Commit

Permalink
feat(embeddings): add embedding dimensions request field (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
EliasJorgensen authored Apr 7, 2024
1 parent aaca8ad commit 413a4d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ class TestEmbeddings : TestOpenAI() {
assertEquals(0, embedding.index)
}

@Test
fun embeddingDimensions() = test {
val response = openAI.embeddings(request = embeddingRequest {
model = ModelId("text-embedding-3-small")
input = listOf("The food was delicious and the waiter...")
dimensions = 1024
})
assertTrue { response.embeddings.isNotEmpty() }
val embedding = response.embeddings.first()
assertTrue { embedding.embedding.isNotEmpty() }
assertEquals(1024, embedding.embedding.size)
assertEquals(0, embedding.index)
}

@Test
fun similarityEqual() = test {
val embedding1 = Embedding(embedding = listOf(1.0, 2.0, 3.0, 4.0), index = 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public class EmbeddingRequest(
*/
@SerialName("input") public val input: List<String>,

/**
* The number of dimensions the resulting output embeddings should have.
*
* Only supported in text-embedding-3 and later models.
*/
@SerialName("dimensions") public val dimensions: Int? = null,

/**
* A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse.
*/
Expand Down Expand Up @@ -59,6 +66,13 @@ public class EmbeddingRequestBuilder {
*/
public var input: List<String>? = null

/**
* The number of dimensions the resulting output embeddings should have.
*
* Only supported in text-embedding-3 and later models.
*/
public var dimensions: Int? = null

/**
* A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse.
*/
Expand All @@ -70,6 +84,7 @@ public class EmbeddingRequestBuilder {
public fun build(): EmbeddingRequest = EmbeddingRequest(
model = requireNotNull(model) { "model is required" },
input = requireNotNull(input) { "input is required" },
dimensions = dimensions,
user = user
)
}

0 comments on commit 413a4d4

Please sign in to comment.