@@ -13,28 +13,29 @@ export class Embeddings extends APIResource {
13
13
) : Core . APIPromise < CreateEmbeddingResponse > {
14
14
Core . debug ( 'request' , 'Sending request with arguments:' , { body, ...options } ) ;
15
15
16
- const hasUserProvidedEncodingFormat = body . encoding_format !== undefined ;
17
- let encoding_format : 'float' | 'base64' = 'float' ; // current API defaults to float
16
+ const hasUserProvidedEncodingFormat = ! ! body . encoding_format ;
17
+ let encoding_format : EmbeddingCreateParams [ 'encoding_format' ] =
18
+ hasUserProvidedEncodingFormat ? body . encoding_format : 'base64' ;
18
19
19
- if ( hasUserProvidedEncodingFormat === false ) {
20
+ if ( hasUserProvidedEncodingFormat ) {
21
+ Core . debug ( 'Request' , 'User defined encoding_format:' , body . encoding_format ) ;
22
+ } else {
20
23
// No encoding_format specified, defaulting to base64 for performance reasons
21
24
// See https://github.com/openai/openai-node/pull/1312
22
25
encoding_format = 'base64' ;
23
- } else {
24
- Core . debug ( 'Request' , 'User defined encoding_format:' , body . encoding_format ) ;
25
26
}
26
27
27
- const response = this . _client . post < EmbeddingCreateParams , CreateEmbeddingResponse > ( '/embeddings' , {
28
+ const response = this . _client . post ( '/embeddings' , {
28
29
body : {
29
30
...body ,
30
- encoding_format,
31
+ encoding_format : encoding_format as EmbeddingCreateParams [ 'encoding_format' ] ,
31
32
} ,
32
33
...options ,
33
34
} ) ;
34
35
35
36
// if the user specified an encoding_format, return the response as-is
36
37
if ( hasUserProvidedEncodingFormat ) {
37
- return response ;
38
+ return response as Core . APIPromise < CreateEmbeddingResponse > ;
38
39
}
39
40
40
41
// in this stage, we are sure the user did not specify an encoding_format
@@ -44,7 +45,7 @@ export class Embeddings extends APIResource {
44
45
Core . debug ( 'response' , `User requested encoding_format=${ encoding_format || 'default' } ` ) ;
45
46
Core . debug ( 'response' , 'Decoding base64 embeddings to float32 array' ) ;
46
47
47
- return response . _thenUnwrap ( ( response ) => {
48
+ return ( response as Core . APIPromise < CreateEmbeddingResponse > ) . _thenUnwrap ( ( response ) => {
48
49
if ( response && response . data ) {
49
50
response . data . forEach ( ( embeddingBase64Obj ) => {
50
51
const embeddingBase64Str = embeddingBase64Obj . embedding as unknown as string ;
0 commit comments