Skip to content

Commit

Permalink
Merge pull request #45 from CJCrafter/embeddings-dimensions
Browse files Browse the repository at this point in the history
Embeddings dimensions
  • Loading branch information
CJCrafter authored Mar 21, 2024
2 parents 11ed06e + 2137373 commit faae5f3
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import com.fasterxml.jackson.annotation.JsonProperty
* @property input The input(s) to convert to embeddings.
* @property model Which [model](https://platform.openai.com/docs/models/embeddings) to use to generate the embeddings.
* @property encodingFormat Determines how the embeddings are encoded. Defaults to [EncodingFormat.FLOAT].
* @property dimensions The number of dimensions to use for the embeddings.
* @property user The user ID to associate with this request.
* @constructor Create empty Embeddings request
*/
data class EmbeddingsRequest internal constructor(
var input: Any,
var model: String,
@JsonProperty("encoding_format") var encodingFormat: EncodingFormat? = null,
var dimensions: Int? = null,
var user: String? = null,
) {

Expand All @@ -30,20 +32,23 @@ data class EmbeddingsRequest internal constructor(
private var input: Any? = null
private var model: String? = null
private var encodingFormat: EncodingFormat? = null
private var dimensions: Int? = null
private var user: String? = null

fun input(input: String) = apply { this.input = input }
fun input(input: List<String>) = apply { this.input = input }
fun model(model: String) = apply { this.model = model }
fun encodingFormat(encodingFormat: EncodingFormat) = apply { this.encodingFormat = encodingFormat }
fun dimensions(dimensions: Int) = apply { this.dimensions = dimensions }
fun user(user: String) = apply { this.user = user }

fun build(): EmbeddingsRequest {
return EmbeddingsRequest(
input = input ?: throw IllegalStateException("input must be defined to use EmbeddingsRequest"),
model = model ?: throw IllegalStateException("model must be defined to use EmbeddingsRequest"),
encodingFormat = encodingFormat,
user = user
dimensions = dimensions,
user = user,
)
}
}
Expand Down

0 comments on commit faae5f3

Please sign in to comment.