Debian Codegraph @

vertexai/genai/tokenizer/example_test.go

raw
1 // Copyright 2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 package tokenizer_test
15
16 import (
17 "fmt"
18 "log"
19
20 "cloud.google.com/go/vertexai/genai"
21 "cloud.google.com/go/vertexai/genai/tokenizer"
22 )
23
24 func ExampleTokenizer_CountTokens() {
25 tok, err := tokenizer.New("gemini-1.5-flash")
26 if err != nil {
27 log.Fatal(err)
28 }
29
30 ntoks, err := tok.CountTokens(genai.Text("a prompt"), genai.Text("another prompt"))
31 if err != nil {
32 log.Fatal(err)
33 }
34
35 fmt.Println("total token count:", ntoks.TotalTokens)
36
37 // Output: total token count: 4
38 }