1.0.19 • Published 2 months ago

js-tiktoken v1.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

⏳ 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

Lite

You can only load the ranks you need, which will significantly reduce the bundle size:

import { Tiktoken } from "js-tiktoken/lite";
import o200k_base from "js-tiktoken/ranks/o200k_base";

const enc = new Tiktoken(o200k_base);
assert(enc.decode(enc.encode("hello world")) === "hello world");

Alternatively, encodings can be loaded dynamically from our CDN hosted on Cloudflare Pages.

import { Tiktoken } from "js-tiktoken/lite";

const res = await fetch(`https://tiktoken.pages.dev/js/o200k_base.json`);
const o200k_base = await res.json();

const enc = new Tiktoken(o200k_base);
assert(enc.decode(enc.encode("hello world")) === "hello world");

Full usage

If you need all the OpenAI tokenizers, you can import the entire library:

!CAUTION This will include all the OpenAI tokenizers, which may significantly increase the bundle size. See

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

const enc = getEncoding("gpt2");
assert(enc.decode(enc.encode("hello world")) === "hello world");
@dingyi222666/chathub-llm-core@everything-registry/sub-chunk-1978@chainlit/clientcustom-gpt-usertalkpilesparkai-jssparkaiv2-jssparkaiv3-jssparkaiv4-jssparkaiv5-jssparkaiv6-jssparkaiv7-js@continuedev/core@copilotkit/backend@digitalgp/langchain-oracle@dingyi222666/koishi-plugin-chathubjoplin-plugin-jarvislanggraph-hitllangchainlangchain-corelangchain-edge-fixfastgpt-global-xyqsparkaiv8-jssosc-ai-testingty-sdktranslation-agenttokensizets-chat@anysphere/priompt-preview@ai-jsx/openai@basproul/core@chatgptweb/chatgpt-api@chat-bot/core@chat1/chatgpt@chiefry/chatgpt@chatluna/core@cognum-factory/langchain@coderabbitai/openai-chat-tokens@colibryx/langchainyilangchainyhh_chatgptunitokenuniversal-llm-completionundetermini@hdr/browser@foundation0/tokenizers@husniadil/codebase-analyzer@floe/trpc@garviand/llamaindex@gaolingtech/chatgpt-api@langchain/textsplitters@llamaindex/edge@logicleai/llmosaic@langtail/openai-chat-tokens@langtrase/trace-attributes@langtrase/typescript-sdk@langchain/core@langchain/openai@langchain/azure-openai@leikeduntech/leiai-js@lgrammel/ai-utils@matheus-santos-souza/langchainjs-oracle-v2@exadev/breadboard-kits@encrejs/core@fallard84/langchain@metalumna/langchain@mirari/chatgpt-api@kemis/harvey-ai@intellidimension/faqtiv-agent-toolkit@jill64/cf-tiktoken@kloblic/chatgpt-k@jschang19/llamaindex@juankeith/zake@juukee/chatgpt@regscale/regml-ex-extractor@readme/langchain@one-beyond-ai/tokenizer@paulkinlan/claude-breadboard-kit@pezzo/copilotkit-backend@orama/chunker@optimaxer/optimaxer-cli@pensar/cli@sourcegraph/cody-shared@skadefro/litellmmodelfusionmistral-tokenizer-esmmistral-tokenizer-tsopenlitoplangchainopenai-chat-tokensopenai-tokensopenai-tokens-countsecret-ai-base-sdkscoreai-jsnode-chatgpt-apiperforea-jspercorea-jsperdorea-jsperabcorea-jsperacorea-js
1.0.19

2 months ago

1.0.18

3 months ago

1.0.17

3 months ago

1.0.16

4 months ago

1.0.15

7 months ago

1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

12 months ago

1.0.11

1 year ago

1.0.9

1 year ago

1.0.10

1 year ago

1.0.8

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0

2 years ago