Skip to content

Commit 7949c97

Browse files
authored
improvement: generativeaionvertexai_gemini_safety_settings and generativeaionvertexai_gemini_token_count (#3878)
* improvement: generativeaionvertexai_gemini_safety_settings * improvement: generativeaionvertexai_gemini_token_count
1 parent 22522ca commit 7949c97

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

generative-ai/snippets/count-tokens/countTokens.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ async function countTokens(
3535
contents: [{role: 'user', parts: [{text: 'How are you doing today?'}]}],
3636
};
3737

38+
// Prompt tokens count
3839
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);
4048
}
4149
// [END generativeaionvertexai_gemini_token_count]
4250

generative-ai/snippets/safetySettings.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ async function setSafetySettings() {
4040
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
4141
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
4242
},
43+
{
44+
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
45+
threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
46+
},
4347
],
44-
generation_config: {
45-
max_output_tokens: 256,
46-
temperature: 0.4,
47-
top_p: 1,
48-
top_k: 16,
49-
},
5048
});
5149

5250
const request = {

0 commit comments

Comments
 (0)