Skip to content

Commit 06ff541

Browse files
authored
Add new struct filed dimensions for embedding API (#645)
* add new struct filed dimensions for embedding API * docs: remove long single-line comments * change embedding request param Dimensions type to int
1 parent 4c41f24 commit 06ff541

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

embeddings.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ type EmbeddingRequest struct {
157157
Model EmbeddingModel `json:"model"`
158158
User string `json:"user"`
159159
EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"`
160+
// Dimensions The number of dimensions the resulting output embeddings should have.
161+
// Only supported in text-embedding-3 and later models.
162+
Dimensions int `json:"dimensions,omitempty"`
160163
}
161164

162165
func (r EmbeddingRequest) Convert() EmbeddingRequest {
@@ -181,6 +184,9 @@ type EmbeddingRequestStrings struct {
181184
// Currently, only "float" and "base64" are supported, however, "base64" is not officially documented.
182185
// If not specified OpenAI will use "float".
183186
EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"`
187+
// Dimensions The number of dimensions the resulting output embeddings should have.
188+
// Only supported in text-embedding-3 and later models.
189+
Dimensions int `json:"dimensions,omitempty"`
184190
}
185191

186192
func (r EmbeddingRequestStrings) Convert() EmbeddingRequest {
@@ -189,6 +195,7 @@ func (r EmbeddingRequestStrings) Convert() EmbeddingRequest {
189195
Model: r.Model,
190196
User: r.User,
191197
EncodingFormat: r.EncodingFormat,
198+
Dimensions: r.Dimensions,
192199
}
193200
}
194201

@@ -209,6 +216,9 @@ type EmbeddingRequestTokens struct {
209216
// Currently, only "float" and "base64" are supported, however, "base64" is not officially documented.
210217
// If not specified OpenAI will use "float".
211218
EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"`
219+
// Dimensions The number of dimensions the resulting output embeddings should have.
220+
// Only supported in text-embedding-3 and later models.
221+
Dimensions int `json:"dimensions,omitempty"`
212222
}
213223

214224
func (r EmbeddingRequestTokens) Convert() EmbeddingRequest {
@@ -217,6 +227,7 @@ func (r EmbeddingRequestTokens) Convert() EmbeddingRequest {
217227
Model: r.Model,
218228
User: r.User,
219229
EncodingFormat: r.EncodingFormat,
230+
Dimensions: r.Dimensions,
220231
}
221232
}
222233

0 commit comments

Comments
 (0)