File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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]
You can’t perform that action at this time.
0 commit comments