To use the tokenizer in your Go application, use tokenizer.Get() to retrieve an encoding instance (e.g., tokenizer.Cl100kBase). Once you have an encoding instance, you can use .Encode(text) to convert a string into a slice of token IDs, and .Decode(ids) to convert token IDs back into a string.
Note that Encode returns three values: the slice of IDs, a slice of special tokens (if any), and an error. Decode returns the decoded string and an error.
package main
import (
"fmt"
"github.com/tiktoken-go/tokenizer"
)
func main() {
enc, err := tokenizer.Get(tokenizer.Cl100kBase)
if err != nil {
panic("oh oh")
}
// this should print a list of token ids
ids, _, _ := enc.Encode("supercalifragilistic")
fmt.Println(ids)
// this should print the original string back
text, _ := enc.Decode(ids)
fmt.Println(text)
}