File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 18
18
import { CountTokensRequest , CountTokensResponse , RequestOptions } from '../types' ;
19
19
import { Task , makeRequest } from '../requests/request' ;
20
20
import { ApiSettings } from '../types/internal' ;
21
+ import { BackendType } from '../public-types' ;
22
+ import * as GoogleAIMapper from '../googleai-mappers' ;
21
23
22
24
export async function countTokens (
23
25
apiSettings : ApiSettings ,
24
26
model : string ,
25
27
params : CountTokensRequest ,
26
28
requestOptions ?: RequestOptions ,
27
29
) : Promise < CountTokensResponse > {
30
+ let body : string = '' ;
31
+ if ( apiSettings . backend . backendType === BackendType . GOOGLE_AI ) {
32
+ const mappedParams = GoogleAIMapper . mapCountTokensRequest ( params , model ) ;
33
+ body = JSON . stringify ( mappedParams ) ;
34
+ } else {
35
+ body = JSON . stringify ( params ) ;
36
+ }
28
37
const response = await makeRequest (
29
38
model ,
30
39
Task . COUNT_TOKENS ,
31
40
apiSettings ,
32
41
false ,
33
- JSON . stringify ( params ) ,
42
+ body ,
34
43
requestOptions ,
35
44
) ;
36
45
return response . json ( ) ;
You can’t perform that action at this time.
0 commit comments