bpe-lite 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpe-lite",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Offline BPE tokenizer for OpenAI, Anthropic, and Gemini — zero dependencies",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
package/src/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
+ const zlib = require('zlib');
5
6
  const { Tokenizer } = require('./tokenizer');
6
7
 
7
8
  const VOCABS_DIR = path.join(__dirname, '..', 'vocabs');
@@ -12,15 +13,21 @@ const _cache = {};
12
13
  function loadTokenizer(provider) {
13
14
  if (_cache[provider]) return _cache[provider];
14
15
 
15
- const filePath = path.join(VOCABS_DIR, `${provider}.json`);
16
- if (!fs.existsSync(filePath)) {
16
+ const gzPath = path.join(VOCABS_DIR, `${provider}.json.gz`);
17
+ const jsonPath = path.join(VOCABS_DIR, `${provider}.json`);
18
+
19
+ let data;
20
+ if (fs.existsSync(gzPath)) {
21
+ data = JSON.parse(zlib.gunzipSync(fs.readFileSync(gzPath)).toString('utf8'));
22
+ } else if (fs.existsSync(jsonPath)) {
23
+ data = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
24
+ } else {
17
25
  throw new Error(
18
- `Vocab file not found for provider "${provider}": ${filePath}\n` +
26
+ `Vocab file not found for provider "${provider}".\n` +
19
27
  'Run "node scripts/build-vocabs.js" to build vocab files.'
20
28
  );
21
29
  }
22
30
 
23
- const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
24
31
  _cache[provider] = new Tokenizer(data);
25
32
  return _cache[provider];
26
33
  }
Binary file