-
-
Save tswistak/70ffb31330105cab8758a26e3f549936 to your computer and use it in GitHub Desktop.
tiktoken-example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { encoding_for_model } from "tiktoken"; | |
| const enc = encoding_for_model("gpt-5"); | |
| const tokens = enc.encode("A świstak siedzi i zawija je w te sreberka"); | |
| console.log(tokens); | |
| const dec = []; | |
| tokens.forEach((t) => { | |
| const decoded = enc.decode([t]); | |
| const decodedStr = String.fromCharCode.apply(null, decoded); | |
| dec.push(decodedStr); | |
| }); | |
| console.log(dec); | |
| enc.free(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment