Skip to content

Commit fc87e46

Browse files
authored
Merge pull request #134 from dqbd/dqbd/js-readme
Update guidance on lite
2 parents e3437a3 + 77ba758 commit fc87e46

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

.changeset/tame-turkeys-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"js-tiktoken": patch
3+
---
4+
5+
Update guidance on lite

js/README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,36 @@ Install the library from NPM:
99
npm install js-tiktoken
1010
```
1111

12-
## Usage
12+
## Lite
1313

14-
Basic usage follows, which includes all the OpenAI encoders and ranks:
14+
You can only load the ranks you need, which will significantly reduce the bundle size:
15+
16+
```typescript
17+
import { Tiktoken } from "js-tiktoken/lite";
18+
import o200k_base from "js-tiktoken/ranks/o200k_base";
19+
20+
const enc = new Tiktoken(o200k_base);
21+
assert(enc.decode(enc.encode("hello world")) === "hello world");
22+
```
23+
24+
Alternatively, encodings can be loaded dynamically from our CDN hosted on Cloudflare Pages.
25+
26+
```typescript
27+
import { Tiktoken } from "js-tiktoken/lite";
28+
29+
const res = await fetch(`https://tiktoken.pages.dev/js/o200k_base.json`);
30+
const o200k_base = await res.json();
31+
32+
const enc = new Tiktoken(o200k_base);
33+
assert(enc.decode(enc.encode("hello world")) === "hello world");
34+
```
35+
36+
## Full usage
37+
38+
If you need all the OpenAI tokenizers, you can import the entire library:
39+
40+
> [!CAUTION]
41+
> This will include all the OpenAI tokenizers, which may significantly increase the bundle size. See
1542
1643
```typescript
1744
import assert from "node:assert";

0 commit comments

Comments
 (0)