File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " js-tiktoken " : patch
3+ ---
4+
5+ Update guidance on lite
Original file line number Diff line number Diff line change @@ -9,9 +9,36 @@ Install the library from NPM:
99npm 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
1744import assert from " node:assert" ;
You can’t perform that action at this time.
0 commit comments