Skip to content

Commit 3491bfc

Browse files
Adding count_tokens for rest (#444)
* Adding count_tokens for rest * Update to have same prompt as python example * tests now working
1 parent 8494231 commit 3491bfc

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

samples/rest/count_tokens.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
set -eu
2+
3+
echo "[START tokens_text_only]"
4+
# [START tokens_text_only]
5+
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:countTokens?key=$GOOGLE_API_KEY \
6+
-H 'Content-Type: application/json' \
7+
-X POST \
8+
-d '{
9+
"contents": [{
10+
"parts":[{
11+
"text": "The quick brown fox jumps over the lazy dog."
12+
}],
13+
}],
14+
}'
15+
# [END tokens_text_only]
16+
17+
echo "[START tokens_chat]"
18+
# [START tokens_chat]
19+
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:countTokens?key=$GOOGLE_API_KEY \
20+
-H 'Content-Type: application/json' \
21+
-X POST \
22+
-d '{
23+
"contents": [
24+
{"role": "user",
25+
"parts": [{"text": "Hi, my name is Bob."}],
26+
},
27+
{"role": "model",
28+
"parts":[{"text": "Hi Bob"}],
29+
},
30+
],
31+
}'
32+
# [END tokens_chat]

0 commit comments

Comments
 (0)