JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1416005
  • Score
    100M100P100Q195849F
  • License MIT

JavaScript port of tiktoken

Package Exports

  • js-tiktoken
  • js-tiktoken/lite
  • js-tiktoken/ranks/cl100k_base
  • js-tiktoken/ranks/gpt2
  • js-tiktoken/ranks/o200k_base
  • js-tiktoken/ranks/p50k_base
  • js-tiktoken/ranks/p50k_edit
  • js-tiktoken/ranks/r50k_base

Readme

⏳ js-tiktoken

tiktoken is a BPE tokeniser for use with OpenAI's models. This is a pure JS port of the original tiktoken library.

Install the library from NPM:

npm install js-tiktoken

Usage

Basic usage follows, which includes all the OpenAI encoders and ranks:

import assert from "node:assert";
import { getEncoding, encodingForModel } from "js-tiktoken";

const enc = getEncoding("gpt2");
assert(enc.decode(enc.encode("hello world")) === "hello world");