MCPcopy Index your code
hub / github.com/botisan-ai/gpt3-tokenizer

github.com/botisan-ai/gpt3-tokenizer @v1.1.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.5 ↗ · + Follow
25 symbols 33 edges 11 files 0 documented · 0% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

GPT3 Tokenizer

Build NPM Version NPM Downloads

This is a isomorphic TypeScript tokenizer for OpenAI's GPT-3 model. Including support for gpt3 and codex tokenization. It should work in both NodeJS and Browser environments.

Usage

First, install:

yarn add gpt3-tokenizer

In code:

import GPT3Tokenizer from 'gpt3-tokenizer';

const tokenizer = new GPT3Tokenizer({ type: 'gpt3' }); // or 'codex'
const str = "hello 👋 world 🌍";
const encoded: { bpe: number[]; text: string[] } = tokenizer.encode(str);
const decoded = tokenizer.decode(encoded.bpe);

Reference

This library is based on the following: - OpenAI Tokenizer Page Source - gpt-3-encoder

The main difference between this library and gpt-3-encoder is that this library supports both gpt3 and codex tokenization (The dictionary is taken directly from OpenAI so the tokenization result is on par with the OpenAI Playground). Also Map API is used instead of JavaScript objects, especially the bpeRanks object, which should see some performance improvement.

License

MIT

Core symbols most depended-on inside this repo

Shape

Function 12
Class 7
Method 6

Languages

TypeScript100%

Modules by API surface

src/tokenizer.ts12 symbols
src/index.ts5 symbols
src/index-browser.ts5 symbols
src/array-keyed-map.d.ts2 symbols
tsdx.config.js1 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add gpt3-tokenizer \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page