Skip to content

Instantly share code, notes, and snippets.

@tswistak
Created April 29, 2026 17:12
Show Gist options
  • Select an option

  • Save tswistak/70ffb31330105cab8758a26e3f549936 to your computer and use it in GitHub Desktop.

Select an option

Save tswistak/70ffb31330105cab8758a26e3f549936 to your computer and use it in GitHub Desktop.
tiktoken-example
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