@@ -17,6 +17,7 @@ import com.openai.core.immutableEmptyMap
17
17
import com.openai.core.toImmutable
18
18
import com.openai.errors.OpenAIInvalidDataException
19
19
import java.util.Objects
20
+ import java.util.Optional
20
21
21
22
/* * Represents an embedding vector returned by embedding endpoint. */
22
23
@NoAutoDetect
@@ -25,7 +26,7 @@ class Embedding
25
26
private constructor (
26
27
@JsonProperty(" embedding" )
27
28
@ExcludeMissing
28
- private val embedding: JsonField <List < Double > > = JsonMissing .of(),
29
+ private val embedding: JsonField <EmbeddingValue > = JsonMissing .of(),
29
30
@JsonProperty(" index" ) @ExcludeMissing private val index: JsonField <Long > = JsonMissing .of(),
30
31
@JsonProperty(" object" ) @ExcludeMissing private val object_: JsonValue = JsonMissing .of(),
31
32
@JsonAnySetter private val additionalProperties: Map <String , JsonValue > = immutableEmptyMap(),
@@ -35,7 +36,7 @@ private constructor(
35
36
* The embedding vector, which is a list of floats. The length of vector depends on the model as
36
37
* listed in the [embedding guide](https://platform.openai.com/docs/guides/embeddings).
37
38
*/
38
- fun embedding (): List < Double > = embedding.getRequired(" embedding" )
39
+ fun embedding (): EmbeddingValue = embedding.getRequired(" embedding" )
39
40
40
41
/* * The index of the embedding in the list of embeddings. */
41
42
fun index (): Long = index.getRequired(" index" )
@@ -47,7 +48,9 @@ private constructor(
47
48
* The embedding vector, which is a list of floats. The length of vector depends on the model as
48
49
* listed in the [embedding guide](https://platform.openai.com/docs/guides/embeddings).
49
50
*/
50
- @JsonProperty(" embedding" ) @ExcludeMissing fun _embedding (): JsonField <List <Double >> = embedding
51
+ @JsonProperty(" embedding" )
52
+ @ExcludeMissing
53
+ fun _embedding (): JsonField <EmbeddingValue > = embedding
51
54
52
55
/* * The index of the embedding in the list of embeddings. */
53
56
@JsonProperty(" index" ) @ExcludeMissing fun _index (): JsonField <Long > = index
@@ -92,14 +95,21 @@ private constructor(
92
95
/* * A builder for [Embedding]. */
93
96
class Builder internal constructor() {
94
97
95
- private var embedding: JsonField <MutableList < Double > >? = null
98
+ private var embedding: JsonField <EmbeddingValue >? = null
96
99
private var index: JsonField <Long >? = null
97
100
private var object_: JsonValue = JsonValue .from(" embedding" )
98
101
private var additionalProperties: MutableMap <String , JsonValue > = mutableMapOf ()
99
102
100
103
@JvmSynthetic
101
104
internal fun from (embedding : Embedding ) = apply {
102
- this .embedding = embedding.embedding.map { it.toMutableList() }
105
+ this .embedding =
106
+ embedding.embedding.map {
107
+ EmbeddingValue (
108
+ floatEmbedding =
109
+ Optional .of(it.floatEmbedding.orElse(mutableListOf ()).toMutableList()),
110
+ base64Embedding = it.base64Embedding,
111
+ )
112
+ }
103
113
index = embedding.index
104
114
object_ = embedding.object_
105
115
additionalProperties = embedding.additionalProperties.toMutableMap()
@@ -110,27 +120,32 @@ private constructor(
110
120
* model as listed in the
111
121
* [embedding guide](https://platform.openai.com/docs/guides/embeddings).
112
122
*/
113
- fun embedding (embedding : List < Double > ) = embedding(JsonField .of(embedding))
123
+ fun embedding (embedding : EmbeddingValue ) = embedding(JsonField .of(embedding))
114
124
115
125
/* *
116
- * The embedding vector, which is a list of floats. The length of vector depends on the
117
- * model as listed in the
126
+ * The embedding vector, which is a list of floats or Base64 . The float length of vector
127
+ * depends on the model as listed in the
118
128
* [embedding guide](https://platform.openai.com/docs/guides/embeddings).
119
129
*/
120
- fun embedding (embedding : JsonField <List <Double >>) = apply {
121
- this .embedding = embedding.map { it.toMutableList() }
130
+ fun embedding (embedding : JsonField <EmbeddingValue >) = apply {
131
+ this .embedding =
132
+ embedding.map {
133
+ EmbeddingValue (
134
+ floatEmbedding =
135
+ Optional .of(it.floatEmbedding.orElse(mutableListOf ()).toMutableList()),
136
+ base64Embedding = it.base64Embedding,
137
+ )
138
+ }
122
139
}
123
140
124
141
/* *
125
- * The embedding vector, which is a list of floats. The length of vector depends on the
126
- * model as listed in the
142
+ * The embedding vector, which is a list of floats or Base64 . The float length of vector
143
+ * depends on the model as listed in the
127
144
* [embedding guide](https://platform.openai.com/docs/guides/embeddings).
128
145
*/
129
- fun addEmbedding (embedding : Double ) = apply {
146
+ fun addEmbedding (embedding : EmbeddingValue ) = apply {
130
147
this .embedding =
131
- (this .embedding ? : JsonField .of(mutableListOf ())).also {
132
- checkKnown(" embedding" , it).add(embedding)
133
- }
148
+ (this .embedding ? : JsonField .of(embedding)).also { checkKnown(" embedding" , it) }
134
149
}
135
150
136
151
/* * The index of the embedding in the list of embeddings. */
@@ -163,7 +178,13 @@ private constructor(
163
178
164
179
fun build (): Embedding =
165
180
Embedding (
166
- checkRequired(" embedding" , embedding).map { it.toImmutable() },
181
+ checkRequired(" embedding" , embedding).map {
182
+ EmbeddingValue (
183
+ floatEmbedding =
184
+ Optional .of(it.floatEmbedding.orElse(mutableListOf ()).toMutableList()),
185
+ base64Embedding = it.base64Embedding,
186
+ )
187
+ },
167
188
checkRequired(" index" , index),
168
189
object_,
169
190
additionalProperties.toImmutable(),
0 commit comments