File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,16 @@ async function countTokens(
35
35
contents : [ { role : 'user' , parts : [ { text : 'How are you doing today?' } ] } ] ,
36
36
} ;
37
37
38
+ // Prompt tokens count
38
39
const countTokensResp = await generativeModel . countTokens ( req ) ;
39
- console . log ( 'count tokens response: ' , countTokensResp ) ;
40
+ console . log ( 'Prompt tokens count: ' , countTokensResp ) ;
41
+
42
+ // Send text to gemini
43
+ const result = await generativeModel . generateContent ( req ) ;
44
+
45
+ // Response tokens count
46
+ const usageMetadata = result . response . usageMetadata ;
47
+ console . log ( 'Response tokens count: ' , usageMetadata ) ;
40
48
}
41
49
// [END generativeaionvertexai_gemini_token_count]
42
50
Original file line number Diff line number Diff line change @@ -40,13 +40,11 @@ async function setSafetySettings() {
40
40
category : HarmCategory . HARM_CATEGORY_DANGEROUS_CONTENT ,
41
41
threshold : HarmBlockThreshold . BLOCK_LOW_AND_ABOVE ,
42
42
} ,
43
+ {
44
+ category : HarmCategory . HARM_CATEGORY_HARASSMENT ,
45
+ threshold : HarmBlockThreshold . BLOCK_LOW_AND_ABOVE ,
46
+ } ,
43
47
] ,
44
- generation_config : {
45
- max_output_tokens : 256 ,
46
- temperature : 0.4 ,
47
- top_p : 1 ,
48
- top_k : 16 ,
49
- } ,
50
48
} ) ;
51
49
52
50
const request = {
You can’t perform that action at this time.
0 commit comments