@@ -13,28 +13,29 @@ export class Embeddings extends APIResource {
1313 ) : Core . APIPromise < CreateEmbeddingResponse > {
1414 Core . debug ( 'request' , 'Sending request with arguments:' , { body, ...options } ) ;
1515
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' ;
1819
19- if ( hasUserProvidedEncodingFormat === false ) {
20+ if ( hasUserProvidedEncodingFormat ) {
21+ Core . debug ( 'Request' , 'User defined encoding_format:' , body . encoding_format ) ;
22+ } else {
2023 // No encoding_format specified, defaulting to base64 for performance reasons
2124 // See https://github.com/openai/openai-node/pull/1312
2225 encoding_format = 'base64' ;
23- } else {
24- Core . debug ( 'Request' , 'User defined encoding_format:' , body . encoding_format ) ;
2526 }
2627
27- const response = this . _client . post < EmbeddingCreateParams , CreateEmbeddingResponse > ( '/embeddings' , {
28+ const response = this . _client . post ( '/embeddings' , {
2829 body : {
2930 ...body ,
30- encoding_format,
31+ encoding_format : encoding_format as EmbeddingCreateParams [ 'encoding_format' ] ,
3132 } ,
3233 ...options ,
3334 } ) ;
3435
3536 // if the user specified an encoding_format, return the response as-is
3637 if ( hasUserProvidedEncodingFormat ) {
37- return response ;
38+ return response as Core . APIPromise < CreateEmbeddingResponse > ;
3839 }
3940
4041 // in this stage, we are sure the user did not specify an encoding_format
@@ -44,7 +45,7 @@ export class Embeddings extends APIResource {
4445 Core . debug ( 'response' , `User requested encoding_format=${ encoding_format || 'default' } ` ) ;
4546 Core . debug ( 'response' , 'Decoding base64 embeddings to float32 array' ) ;
4647
47- return response . _thenUnwrap ( ( response ) => {
48+ return ( response as Core . APIPromise < CreateEmbeddingResponse > ) . _thenUnwrap ( ( response ) => {
4849 if ( response && response . data ) {
4950 response . data . forEach ( ( embeddingBase64Obj ) => {
5051 const embeddingBase64Str = embeddingBase64Obj . embedding as unknown as string ;
0 commit comments