@goliapkg/tiktoken-wasm 3.2.0 → 3.2.2

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/tiktoken_wasm.js CHANGED
@@ -1,638 +1,9 @@
1
1
  /* @ts-self-types="./tiktoken_wasm.d.ts" */
2
2
 
3
- /**
4
- * WASM wrapper around a tiktoken encoding instance.
5
- *
6
- * Created via [`get_encoding`] or [`encoding_for_model`].
7
- * Call `.free()` when done to release WASM memory.
8
- */
9
- export class Encoding {
10
- static __wrap(ptr) {
11
- ptr = ptr >>> 0;
12
- const obj = Object.create(Encoding.prototype);
13
- obj.__wbg_ptr = ptr;
14
- EncodingFinalization.register(obj, obj.__wbg_ptr, obj);
15
- return obj;
16
- }
17
- __destroy_into_raw() {
18
- const ptr = this.__wbg_ptr;
19
- this.__wbg_ptr = 0;
20
- EncodingFinalization.unregister(this);
21
- return ptr;
22
- }
23
- free() {
24
- const ptr = this.__destroy_into_raw();
25
- wasm.__wbg_encoding_free(ptr, 0);
26
- }
27
- /**
28
- * Count tokens without building the full token id array.
29
- *
30
- * Faster than `encode(text).length` for cases where you only need the count.
31
- * @param {string} text
32
- * @returns {number}
33
- */
34
- count(text) {
35
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
- const len0 = WASM_VECTOR_LEN;
37
- const ret = wasm.encoding_count(this.__wbg_ptr, ptr0, len0);
38
- return ret >>> 0;
39
- }
40
- /**
41
- * Count tokens, recognizing special tokens.
42
- *
43
- * Like `count()` but special tokens (e.g. `<|endoftext|>`) are counted
44
- * as single tokens instead of being split into sub-word pieces.
45
- * @param {string} text
46
- * @returns {number}
47
- */
48
- countWithSpecialTokens(text) {
49
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
50
- const len0 = WASM_VECTOR_LEN;
51
- const ret = wasm.encoding_countWithSpecialTokens(this.__wbg_ptr, ptr0, len0);
52
- return ret >>> 0;
53
- }
54
- /**
55
- * Decode token ids back to a UTF-8 string.
56
- *
57
- * Uses lossy UTF-8 conversion — invalid byte sequences are replaced with U+FFFD.
58
- * @param {Uint32Array} tokens
59
- * @returns {string}
60
- */
61
- decode(tokens) {
62
- let deferred2_0;
63
- let deferred2_1;
64
- try {
65
- const ptr0 = passArray32ToWasm0(tokens, wasm.__wbindgen_malloc);
66
- const len0 = WASM_VECTOR_LEN;
67
- const ret = wasm.encoding_decode(this.__wbg_ptr, ptr0, len0);
68
- deferred2_0 = ret[0];
69
- deferred2_1 = ret[1];
70
- return getStringFromWasm0(ret[0], ret[1]);
71
- } finally {
72
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
73
- }
74
- }
75
- /**
76
- * Encode text into token ids (returns `Uint32Array` in JS).
77
- *
78
- * Special tokens like `<|endoftext|>` are treated as ordinary text.
79
- * Use `encodeWithSpecialTokens()` to recognize them.
80
- * @param {string} text
81
- * @returns {Uint32Array}
82
- */
83
- encode(text) {
84
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
85
- const len0 = WASM_VECTOR_LEN;
86
- const ret = wasm.encoding_encode(this.__wbg_ptr, ptr0, len0);
87
- var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
88
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
89
- return v2;
90
- }
91
- /**
92
- * Encode text into token ids, recognizing special tokens.
93
- *
94
- * Special tokens (e.g. `<|endoftext|>`) are encoded as their designated ids
95
- * instead of being split into sub-word pieces.
96
- * @param {string} text
97
- * @returns {Uint32Array}
98
- */
99
- encodeWithSpecialTokens(text) {
100
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
101
- const len0 = WASM_VECTOR_LEN;
102
- const ret = wasm.encoding_encodeWithSpecialTokens(this.__wbg_ptr, ptr0, len0);
103
- var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
104
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
105
- return v2;
106
- }
107
- /**
108
- * Get the encoding name (e.g. `"cl100k_base"`).
109
- * @returns {string}
110
- */
111
- get name() {
112
- let deferred1_0;
113
- let deferred1_1;
114
- try {
115
- const ret = wasm.encoding_name(this.__wbg_ptr);
116
- deferred1_0 = ret[0];
117
- deferred1_1 = ret[1];
118
- return getStringFromWasm0(ret[0], ret[1]);
119
- } finally {
120
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
121
- }
122
- }
123
- /**
124
- * Get the number of special tokens in the vocabulary.
125
- * @returns {number}
126
- */
127
- get numSpecialTokens() {
128
- const ret = wasm.encoding_numSpecialTokens(this.__wbg_ptr);
129
- return ret >>> 0;
130
- }
131
- /**
132
- * Get the number of regular (non-special) tokens in the vocabulary.
133
- * @returns {number}
134
- */
135
- get vocabSize() {
136
- const ret = wasm.encoding_vocabSize(this.__wbg_ptr);
137
- return ret >>> 0;
138
- }
139
- }
140
- if (Symbol.dispose) Encoding.prototype[Symbol.dispose] = Encoding.prototype.free;
3
+ import * as wasm from "./tiktoken_wasm_bg.wasm";
4
+ import { __wbg_set_wasm } from "./tiktoken_wasm_bg.js";
5
+ __wbg_set_wasm(wasm);
141
6
 
142
- /**
143
- * Model pricing and metadata.
144
- */
145
- export class ModelInfo {
146
- static __wrap(ptr) {
147
- ptr = ptr >>> 0;
148
- const obj = Object.create(ModelInfo.prototype);
149
- obj.__wbg_ptr = ptr;
150
- ModelInfoFinalization.register(obj, obj.__wbg_ptr, obj);
151
- return obj;
152
- }
153
- __destroy_into_raw() {
154
- const ptr = this.__wbg_ptr;
155
- this.__wbg_ptr = 0;
156
- ModelInfoFinalization.unregister(this);
157
- return ptr;
158
- }
159
- free() {
160
- const ptr = this.__destroy_into_raw();
161
- wasm.__wbg_modelinfo_free(ptr, 0);
162
- }
163
- /**
164
- * @returns {number | undefined}
165
- */
166
- get cachedInputPer1m() {
167
- const ret = wasm.modelinfo_cachedInputPer1m(this.__wbg_ptr);
168
- return ret[0] === 0 ? undefined : ret[1];
169
- }
170
- /**
171
- * @returns {number}
172
- */
173
- get contextWindow() {
174
- const ret = wasm.modelinfo_contextWindow(this.__wbg_ptr);
175
- return ret >>> 0;
176
- }
177
- /**
178
- * @returns {string}
179
- */
180
- get id() {
181
- let deferred1_0;
182
- let deferred1_1;
183
- try {
184
- const ret = wasm.modelinfo_id(this.__wbg_ptr);
185
- deferred1_0 = ret[0];
186
- deferred1_1 = ret[1];
187
- return getStringFromWasm0(ret[0], ret[1]);
188
- } finally {
189
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
190
- }
191
- }
192
- /**
193
- * @returns {number}
194
- */
195
- get inputPer1m() {
196
- const ret = wasm.modelinfo_inputPer1m(this.__wbg_ptr);
197
- return ret;
198
- }
199
- /**
200
- * @returns {number}
201
- */
202
- get maxOutput() {
203
- const ret = wasm.modelinfo_maxOutput(this.__wbg_ptr);
204
- return ret >>> 0;
205
- }
206
- /**
207
- * @returns {number}
208
- */
209
- get outputPer1m() {
210
- const ret = wasm.modelinfo_outputPer1m(this.__wbg_ptr);
211
- return ret;
212
- }
213
- /**
214
- * @returns {string}
215
- */
216
- get provider() {
217
- let deferred1_0;
218
- let deferred1_1;
219
- try {
220
- const ret = wasm.modelinfo_provider(this.__wbg_ptr);
221
- deferred1_0 = ret[0];
222
- deferred1_1 = ret[1];
223
- return getStringFromWasm0(ret[0], ret[1]);
224
- } finally {
225
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
226
- }
227
- }
228
- }
229
- if (Symbol.dispose) ModelInfo.prototype[Symbol.dispose] = ModelInfo.prototype.free;
230
-
231
- /**
232
- * List all supported models with pricing info.
233
- *
234
- * Returns an array of `ModelInfo` objects.
235
- * @returns {ModelInfo[]}
236
- */
237
- export function allModels() {
238
- const ret = wasm.allModels();
239
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
240
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
241
- return v1;
242
- }
243
-
244
- /**
245
- * Get an encoding for a model name (e.g. `"gpt-4o"`, `"o3-mini"`, `"llama-4"`, `"deepseek-r1"`).
246
- *
247
- * Supports models from OpenAI, Meta, DeepSeek, Qwen, and Mistral.
248
- * Automatically resolves the model name to the correct encoding.
249
- * Throws `Error` for unknown model names.
250
- * @param {string} model
251
- * @returns {Encoding}
252
- */
253
- export function encodingForModel(model) {
254
- const ptr0 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
255
- const len0 = WASM_VECTOR_LEN;
256
- const ret = wasm.encodingForModel(ptr0, len0);
257
- if (ret[2]) {
258
- throw takeFromExternrefTable0(ret[1]);
259
- }
260
- return Encoding.__wrap(ret[0]);
261
- }
262
-
263
- /**
264
- * Estimate cost in USD for a given model, input token count, and output token count.
265
- *
266
- * Supports OpenAI, Anthropic Claude, Google Gemini, Meta Llama, DeepSeek, Qwen, and Mistral models.
267
- * Throws `Error` for unknown model ids.
268
- * @param {string} model_id
269
- * @param {number} input_tokens
270
- * @param {number} output_tokens
271
- * @returns {number}
272
- */
273
- export function estimateCost(model_id, input_tokens, output_tokens) {
274
- const ptr0 = passStringToWasm0(model_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
275
- const len0 = WASM_VECTOR_LEN;
276
- const ret = wasm.estimateCost(ptr0, len0, input_tokens, output_tokens);
277
- if (ret[2]) {
278
- throw takeFromExternrefTable0(ret[1]);
279
- }
280
- return ret[0];
281
- }
282
-
283
- /**
284
- * Get an encoding by name.
285
- *
286
- * Supported encodings:
287
- * - `"cl100k_base"` — GPT-4, GPT-3.5-turbo
288
- * - `"o200k_base"` — GPT-4o, GPT-4.1, o1, o3
289
- * - `"p50k_base"` — text-davinci-002/003
290
- * - `"p50k_edit"` — text-davinci-edit
291
- * - `"r50k_base"` — GPT-3 (davinci, curie, etc.)
292
- * - `"llama3"` — Meta Llama 3/4
293
- * - `"deepseek_v3"` — DeepSeek V3/R1
294
- * - `"qwen2"` — Qwen 2/2.5/3
295
- * - `"mistral_v3"` — Mistral/Codestral/Pixtral
296
- *
297
- * Throws `Error` for unknown encoding names.
298
- * @param {string} name
299
- * @returns {Encoding}
300
- */
301
- export function getEncoding(name) {
302
- const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
303
- const len0 = WASM_VECTOR_LEN;
304
- const ret = wasm.getEncoding(ptr0, len0);
305
- if (ret[2]) {
306
- throw takeFromExternrefTable0(ret[1]);
307
- }
308
- return Encoding.__wrap(ret[0]);
309
- }
310
-
311
- /**
312
- * Get model pricing and metadata.
313
- *
314
- * Returns a typed object with: `id`, `provider`, `inputPer1m`, `outputPer1m`,
315
- * `cachedInputPer1m`, `contextWindow`, `maxOutput`.
316
- *
317
- * Throws `Error` for unknown model ids.
318
- * @param {string} model_id
319
- * @returns {ModelInfo}
320
- */
321
- export function getModelInfo(model_id) {
322
- const ptr0 = passStringToWasm0(model_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
323
- const len0 = WASM_VECTOR_LEN;
324
- const ret = wasm.getModelInfo(ptr0, len0);
325
- if (ret[2]) {
326
- throw takeFromExternrefTable0(ret[1]);
327
- }
328
- return ModelInfo.__wrap(ret[0]);
329
- }
330
-
331
- /**
332
- * List all available encoding names.
333
- *
334
- * Returns an array of strings: `["cl100k_base", "o200k_base", ...]`
335
- * @returns {any[]}
336
- */
337
- export function listEncodings() {
338
- const ret = wasm.listEncodings();
339
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
340
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
341
- return v1;
342
- }
343
-
344
- /**
345
- * Map a model name to its encoding name without loading the encoding.
346
- *
347
- * Returns the encoding name string (e.g. `"o200k_base"`) or `null` for unknown models.
348
- * @param {string} model
349
- * @returns {string | undefined}
350
- */
351
- export function modelToEncoding(model) {
352
- const ptr0 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
353
- const len0 = WASM_VECTOR_LEN;
354
- const ret = wasm.modelToEncoding(ptr0, len0);
355
- let v2;
356
- if (ret[0] !== 0) {
357
- v2 = getStringFromWasm0(ret[0], ret[1]).slice();
358
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
359
- }
360
- return v2;
361
- }
362
-
363
- /**
364
- * List models filtered by provider name.
365
- *
366
- * Provider names: `"OpenAI"`, `"Anthropic"`, `"Google"`, `"Meta"`, `"DeepSeek"`, `"Alibaba"`, `"Mistral"`.
367
- * Returns an empty array for unknown providers.
368
- * @param {string} provider
369
- * @returns {ModelInfo[]}
370
- */
371
- export function modelsByProvider(provider) {
372
- const ptr0 = passStringToWasm0(provider, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
373
- const len0 = WASM_VECTOR_LEN;
374
- const ret = wasm.modelsByProvider(ptr0, len0);
375
- var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
376
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
377
- return v2;
378
- }
379
-
380
- function __wbg_get_imports() {
381
- const import0 = {
382
- __proto__: null,
383
- __wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
384
- const ret = Error(getStringFromWasm0(arg0, arg1));
385
- return ret;
386
- },
387
- __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
388
- throw new Error(getStringFromWasm0(arg0, arg1));
389
- },
390
- __wbg_modelinfo_new: function(arg0) {
391
- const ret = ModelInfo.__wrap(arg0);
392
- return ret;
393
- },
394
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
395
- // Cast intrinsic for `Ref(String) -> Externref`.
396
- const ret = getStringFromWasm0(arg0, arg1);
397
- return ret;
398
- },
399
- __wbindgen_init_externref_table: function() {
400
- const table = wasm.__wbindgen_externrefs;
401
- const offset = table.grow(4);
402
- table.set(0, undefined);
403
- table.set(offset + 0, undefined);
404
- table.set(offset + 1, null);
405
- table.set(offset + 2, true);
406
- table.set(offset + 3, false);
407
- },
408
- };
409
- return {
410
- __proto__: null,
411
- "./tiktoken_wasm_bg.js": import0,
412
- };
413
- }
414
-
415
- const EncodingFinalization = (typeof FinalizationRegistry === 'undefined')
416
- ? { register: () => {}, unregister: () => {} }
417
- : new FinalizationRegistry(ptr => wasm.__wbg_encoding_free(ptr >>> 0, 1));
418
- const ModelInfoFinalization = (typeof FinalizationRegistry === 'undefined')
419
- ? { register: () => {}, unregister: () => {} }
420
- : new FinalizationRegistry(ptr => wasm.__wbg_modelinfo_free(ptr >>> 0, 1));
421
-
422
- function getArrayJsValueFromWasm0(ptr, len) {
423
- ptr = ptr >>> 0;
424
- const mem = getDataViewMemory0();
425
- const result = [];
426
- for (let i = ptr; i < ptr + 4 * len; i += 4) {
427
- result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
428
- }
429
- wasm.__externref_drop_slice(ptr, len);
430
- return result;
431
- }
432
-
433
- function getArrayU32FromWasm0(ptr, len) {
434
- ptr = ptr >>> 0;
435
- return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
436
- }
437
-
438
- let cachedDataViewMemory0 = null;
439
- function getDataViewMemory0() {
440
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
441
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
442
- }
443
- return cachedDataViewMemory0;
444
- }
445
-
446
- function getStringFromWasm0(ptr, len) {
447
- ptr = ptr >>> 0;
448
- return decodeText(ptr, len);
449
- }
450
-
451
- let cachedUint32ArrayMemory0 = null;
452
- function getUint32ArrayMemory0() {
453
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
454
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
455
- }
456
- return cachedUint32ArrayMemory0;
457
- }
458
-
459
- let cachedUint8ArrayMemory0 = null;
460
- function getUint8ArrayMemory0() {
461
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
462
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
463
- }
464
- return cachedUint8ArrayMemory0;
465
- }
466
-
467
- function passArray32ToWasm0(arg, malloc) {
468
- const ptr = malloc(arg.length * 4, 4) >>> 0;
469
- getUint32ArrayMemory0().set(arg, ptr / 4);
470
- WASM_VECTOR_LEN = arg.length;
471
- return ptr;
472
- }
473
-
474
- function passStringToWasm0(arg, malloc, realloc) {
475
- if (realloc === undefined) {
476
- const buf = cachedTextEncoder.encode(arg);
477
- const ptr = malloc(buf.length, 1) >>> 0;
478
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
479
- WASM_VECTOR_LEN = buf.length;
480
- return ptr;
481
- }
482
-
483
- let len = arg.length;
484
- let ptr = malloc(len, 1) >>> 0;
485
-
486
- const mem = getUint8ArrayMemory0();
487
-
488
- let offset = 0;
489
-
490
- for (; offset < len; offset++) {
491
- const code = arg.charCodeAt(offset);
492
- if (code > 0x7F) break;
493
- mem[ptr + offset] = code;
494
- }
495
- if (offset !== len) {
496
- if (offset !== 0) {
497
- arg = arg.slice(offset);
498
- }
499
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
500
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
501
- const ret = cachedTextEncoder.encodeInto(arg, view);
502
-
503
- offset += ret.written;
504
- ptr = realloc(ptr, len, offset, 1) >>> 0;
505
- }
506
-
507
- WASM_VECTOR_LEN = offset;
508
- return ptr;
509
- }
510
-
511
- function takeFromExternrefTable0(idx) {
512
- const value = wasm.__wbindgen_externrefs.get(idx);
513
- wasm.__externref_table_dealloc(idx);
514
- return value;
515
- }
516
-
517
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
518
- cachedTextDecoder.decode();
519
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
520
- let numBytesDecoded = 0;
521
- function decodeText(ptr, len) {
522
- numBytesDecoded += len;
523
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
524
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
525
- cachedTextDecoder.decode();
526
- numBytesDecoded = len;
527
- }
528
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
529
- }
530
-
531
- const cachedTextEncoder = new TextEncoder();
532
-
533
- if (!('encodeInto' in cachedTextEncoder)) {
534
- cachedTextEncoder.encodeInto = function (arg, view) {
535
- const buf = cachedTextEncoder.encode(arg);
536
- view.set(buf);
537
- return {
538
- read: arg.length,
539
- written: buf.length
540
- };
541
- };
542
- }
543
-
544
- let WASM_VECTOR_LEN = 0;
545
-
546
- let wasmModule, wasm;
547
- function __wbg_finalize_init(instance, module) {
548
- wasm = instance.exports;
549
- wasmModule = module;
550
- cachedDataViewMemory0 = null;
551
- cachedUint32ArrayMemory0 = null;
552
- cachedUint8ArrayMemory0 = null;
553
- wasm.__wbindgen_start();
554
- return wasm;
555
- }
556
-
557
- async function __wbg_load(module, imports) {
558
- if (typeof Response === 'function' && module instanceof Response) {
559
- if (typeof WebAssembly.instantiateStreaming === 'function') {
560
- try {
561
- return await WebAssembly.instantiateStreaming(module, imports);
562
- } catch (e) {
563
- const validResponse = module.ok && expectedResponseType(module.type);
564
-
565
- if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
566
- console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
567
-
568
- } else { throw e; }
569
- }
570
- }
571
-
572
- const bytes = await module.arrayBuffer();
573
- return await WebAssembly.instantiate(bytes, imports);
574
- } else {
575
- const instance = await WebAssembly.instantiate(module, imports);
576
-
577
- if (instance instanceof WebAssembly.Instance) {
578
- return { instance, module };
579
- } else {
580
- return instance;
581
- }
582
- }
583
-
584
- function expectedResponseType(type) {
585
- switch (type) {
586
- case 'basic': case 'cors': case 'default': return true;
587
- }
588
- return false;
589
- }
590
- }
591
-
592
- function initSync(module) {
593
- if (wasm !== undefined) return wasm;
594
-
595
-
596
- if (module !== undefined) {
597
- if (Object.getPrototypeOf(module) === Object.prototype) {
598
- ({module} = module)
599
- } else {
600
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
601
- }
602
- }
603
-
604
- const imports = __wbg_get_imports();
605
- if (!(module instanceof WebAssembly.Module)) {
606
- module = new WebAssembly.Module(module);
607
- }
608
- const instance = new WebAssembly.Instance(module, imports);
609
- return __wbg_finalize_init(instance, module);
610
- }
611
-
612
- async function __wbg_init(module_or_path) {
613
- if (wasm !== undefined) return wasm;
614
-
615
-
616
- if (module_or_path !== undefined) {
617
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
618
- ({module_or_path} = module_or_path)
619
- } else {
620
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
621
- }
622
- }
623
-
624
- if (module_or_path === undefined) {
625
- module_or_path = new URL('tiktoken_wasm_bg.wasm', import.meta.url);
626
- }
627
- const imports = __wbg_get_imports();
628
-
629
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
630
- module_or_path = fetch(module_or_path);
631
- }
632
-
633
- const { instance, module } = await __wbg_load(await module_or_path, imports);
634
-
635
- return __wbg_finalize_init(instance, module);
636
- }
637
-
638
- export { initSync, __wbg_init as default };
7
+ export {
8
+ Encoding, ModelInfo, allModels, encodingForModel, estimateCost, getEncoding, getModelInfo, listEncodings, modelToEncoding, modelsByProvider
9
+ } from "./tiktoken_wasm_bg.js";