@goliapkg/tiktoken-wasm 3.1.0 → 3.2.0
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/README.md +60 -12
- package/package.json +1 -1
- package/tiktoken_wasm.d.ts +82 -6
- package/tiktoken_wasm.js +203 -23
- package/tiktoken_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ wasm-pack build --target web --release
|
|
|
21
21
|
|
|
22
22
|
Output is in `pkg/` — a complete npm-ready package containing:
|
|
23
23
|
- `tiktoken_wasm.js` — ES module with WASM loader
|
|
24
|
-
- `tiktoken_wasm_bg.wasm` — compiled WASM binary (~3 MB)
|
|
24
|
+
- `tiktoken_wasm_bg.wasm` — compiled WASM binary (~7 MB, ~3 MB gzipped)
|
|
25
25
|
- `tiktoken_wasm.d.ts` — TypeScript type definitions
|
|
26
26
|
|
|
27
27
|
## Usage
|
|
@@ -32,37 +32,54 @@ Output is in `pkg/` — a complete npm-ready package containing:
|
|
|
32
32
|
import init, {
|
|
33
33
|
getEncoding,
|
|
34
34
|
encodingForModel,
|
|
35
|
+
listEncodings,
|
|
36
|
+
modelToEncoding,
|
|
35
37
|
estimateCost,
|
|
36
38
|
getModelInfo,
|
|
39
|
+
allModels,
|
|
40
|
+
modelsByProvider,
|
|
37
41
|
type Encoding,
|
|
42
|
+
type ModelInfo,
|
|
38
43
|
} from '@goliapkg/tiktoken-wasm'
|
|
39
44
|
|
|
40
45
|
// initialize WASM module (required once, before any other calls)
|
|
41
46
|
await init()
|
|
42
47
|
|
|
48
|
+
// discover available encodings
|
|
49
|
+
const names: string[] = listEncodings()
|
|
50
|
+
// ["cl100k_base", "o200k_base", ..., "mistral_v3"]
|
|
51
|
+
|
|
43
52
|
// encode / decode
|
|
44
53
|
const enc: Encoding = getEncoding('cl100k_base')
|
|
45
54
|
const tokens: Uint32Array = enc.encode('hello world')
|
|
46
55
|
const text: string = enc.decode(tokens) // "hello world"
|
|
47
56
|
const count: number = enc.count('hello world') // 2
|
|
48
57
|
|
|
58
|
+
// special token handling
|
|
59
|
+
const countST: number = enc.countWithSpecialTokens('hi<|endoftext|>bye')
|
|
60
|
+
|
|
61
|
+
// vocabulary info
|
|
62
|
+
console.log(enc.vocabSize) // 100256
|
|
63
|
+
console.log(enc.numSpecialTokens) // 5
|
|
64
|
+
|
|
49
65
|
// by model name — supports OpenAI, Meta, DeepSeek, Qwen, Mistral
|
|
50
66
|
const enc2 = encodingForModel('gpt-4o')
|
|
51
|
-
const
|
|
52
|
-
const enc4 = encodingForModel('deepseek-r1')
|
|
67
|
+
const encName = modelToEncoding('llama-4-scout') // "llama3"
|
|
53
68
|
|
|
54
69
|
// cost estimation (USD)
|
|
55
70
|
const cost: number = estimateCost('gpt-4o', 1000, 500)
|
|
56
71
|
|
|
57
|
-
// model metadata
|
|
58
|
-
const info = getModelInfo('claude-opus-4')
|
|
59
|
-
|
|
72
|
+
// model metadata (fully typed)
|
|
73
|
+
const info: ModelInfo = getModelInfo('claude-opus-4')
|
|
74
|
+
console.log(info.id, info.provider, info.inputPer1m, info.contextWindow)
|
|
75
|
+
|
|
76
|
+
// browse all models or filter by provider
|
|
77
|
+
const all: ModelInfo[] = allModels()
|
|
78
|
+
const openai: ModelInfo[] = modelsByProvider('OpenAI')
|
|
60
79
|
|
|
61
80
|
// free WASM memory when done
|
|
62
81
|
enc.free()
|
|
63
82
|
enc2.free()
|
|
64
|
-
enc3.free()
|
|
65
|
-
enc4.free()
|
|
66
83
|
```
|
|
67
84
|
|
|
68
85
|
### Bundler Configuration
|
|
@@ -101,6 +118,10 @@ module.exports = {
|
|
|
101
118
|
|
|
102
119
|
## API Reference
|
|
103
120
|
|
|
121
|
+
### `listEncodings(): string[]`
|
|
122
|
+
|
|
123
|
+
List all available encoding names (9 encodings).
|
|
124
|
+
|
|
104
125
|
### `getEncoding(name: string): Encoding`
|
|
105
126
|
|
|
106
127
|
Get a tokenizer by encoding name. Supported:
|
|
@@ -118,24 +139,51 @@ Get a tokenizer by encoding name. Supported:
|
|
|
118
139
|
|
|
119
140
|
Get a tokenizer by model name (e.g. `gpt-4o`, `llama-4-scout`, `deepseek-r1`, `qwen3-235b`).
|
|
120
141
|
|
|
142
|
+
### `modelToEncoding(model: string): string | null`
|
|
143
|
+
|
|
144
|
+
Map a model name to its encoding name without loading the encoding.
|
|
145
|
+
|
|
121
146
|
### `Encoding`
|
|
122
147
|
|
|
123
|
-
| Method |
|
|
124
|
-
|
|
148
|
+
| Method / Property | Type | Description |
|
|
149
|
+
|-------------------|------|-------------|
|
|
125
150
|
| `encode(text)` | `Uint32Array` | Encode text to token ids |
|
|
126
151
|
| `encodeWithSpecialTokens(text)` | `Uint32Array` | Encode with special token recognition |
|
|
127
152
|
| `decode(tokens)` | `string` | Decode token ids to text |
|
|
128
153
|
| `count(text)` | `number` | Count tokens (faster than `encode().length`) |
|
|
154
|
+
| `countWithSpecialTokens(text)` | `number` | Count tokens with special token recognition |
|
|
129
155
|
| `name` | `string` | Encoding name (getter) |
|
|
156
|
+
| `vocabSize` | `number` | Number of regular tokens in vocabulary |
|
|
157
|
+
| `numSpecialTokens` | `number` | Number of special tokens |
|
|
130
158
|
| `free()` | `void` | Release WASM memory |
|
|
131
159
|
|
|
132
160
|
### `estimateCost(modelId, inputTokens, outputTokens): number`
|
|
133
161
|
|
|
134
162
|
Estimate API cost in USD. Supports 57 models across 7 providers.
|
|
135
163
|
|
|
136
|
-
### `getModelInfo(modelId):
|
|
164
|
+
### `getModelInfo(modelId): ModelInfo`
|
|
165
|
+
|
|
166
|
+
Get model metadata with full TypeScript typing.
|
|
167
|
+
|
|
168
|
+
### `allModels(): ModelInfo[]`
|
|
169
|
+
|
|
170
|
+
List all 57 supported models with pricing info.
|
|
171
|
+
|
|
172
|
+
### `modelsByProvider(provider): ModelInfo[]`
|
|
173
|
+
|
|
174
|
+
Filter models by provider: `"OpenAI"`, `"Anthropic"`, `"Google"`, `"Meta"`, `"DeepSeek"`, `"Alibaba"`, `"Mistral"`.
|
|
175
|
+
|
|
176
|
+
### `ModelInfo`
|
|
137
177
|
|
|
138
|
-
|
|
178
|
+
| Property | Type | Description |
|
|
179
|
+
|----------|------|-------------|
|
|
180
|
+
| `id` | `string` | Model identifier |
|
|
181
|
+
| `provider` | `string` | Provider name |
|
|
182
|
+
| `inputPer1m` | `number` | Input cost per 1M tokens (USD) |
|
|
183
|
+
| `outputPer1m` | `number` | Output cost per 1M tokens (USD) |
|
|
184
|
+
| `cachedInputPer1m` | `number \| undefined` | Cached input cost per 1M tokens |
|
|
185
|
+
| `contextWindow` | `number` | Max context window (tokens) |
|
|
186
|
+
| `maxOutput` | `number` | Max output tokens |
|
|
139
187
|
|
|
140
188
|
## Supported Models (pricing)
|
|
141
189
|
|
package/package.json
CHANGED
package/tiktoken_wasm.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export class Encoding {
|
|
|
17
17
|
* Faster than `encode(text).length` for cases where you only need the count.
|
|
18
18
|
*/
|
|
19
19
|
count(text: string): number;
|
|
20
|
+
/**
|
|
21
|
+
* Count tokens, recognizing special tokens.
|
|
22
|
+
*
|
|
23
|
+
* Like `count()` but special tokens (e.g. `<|endoftext|>`) are counted
|
|
24
|
+
* as single tokens instead of being split into sub-word pieces.
|
|
25
|
+
*/
|
|
26
|
+
countWithSpecialTokens(text: string): number;
|
|
20
27
|
/**
|
|
21
28
|
* Decode token ids back to a UTF-8 string.
|
|
22
29
|
*
|
|
@@ -41,8 +48,39 @@ export class Encoding {
|
|
|
41
48
|
* Get the encoding name (e.g. `"cl100k_base"`).
|
|
42
49
|
*/
|
|
43
50
|
readonly name: string;
|
|
51
|
+
/**
|
|
52
|
+
* Get the number of special tokens in the vocabulary.
|
|
53
|
+
*/
|
|
54
|
+
readonly numSpecialTokens: number;
|
|
55
|
+
/**
|
|
56
|
+
* Get the number of regular (non-special) tokens in the vocabulary.
|
|
57
|
+
*/
|
|
58
|
+
readonly vocabSize: number;
|
|
44
59
|
}
|
|
45
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Model pricing and metadata.
|
|
63
|
+
*/
|
|
64
|
+
export class ModelInfo {
|
|
65
|
+
private constructor();
|
|
66
|
+
free(): void;
|
|
67
|
+
[Symbol.dispose](): void;
|
|
68
|
+
readonly cachedInputPer1m: number | undefined;
|
|
69
|
+
readonly contextWindow: number;
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly inputPer1m: number;
|
|
72
|
+
readonly maxOutput: number;
|
|
73
|
+
readonly outputPer1m: number;
|
|
74
|
+
readonly provider: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* List all supported models with pricing info.
|
|
79
|
+
*
|
|
80
|
+
* Returns an array of `ModelInfo` objects.
|
|
81
|
+
*/
|
|
82
|
+
export function allModels(): ModelInfo[];
|
|
83
|
+
|
|
46
84
|
/**
|
|
47
85
|
* Get an encoding for a model name (e.g. `"gpt-4o"`, `"o3-mini"`, `"llama-4"`, `"deepseek-r1"`).
|
|
48
86
|
*
|
|
@@ -79,34 +117,72 @@ export function estimateCost(model_id: string, input_tokens: number, output_toke
|
|
|
79
117
|
export function getEncoding(name: string): Encoding;
|
|
80
118
|
|
|
81
119
|
/**
|
|
82
|
-
* Get model pricing and metadata
|
|
120
|
+
* Get model pricing and metadata.
|
|
83
121
|
*
|
|
84
|
-
* Returns
|
|
85
|
-
* `
|
|
122
|
+
* Returns a typed object with: `id`, `provider`, `inputPer1m`, `outputPer1m`,
|
|
123
|
+
* `cachedInputPer1m`, `contextWindow`, `maxOutput`.
|
|
86
124
|
*
|
|
87
125
|
* Throws `Error` for unknown model ids.
|
|
88
126
|
*/
|
|
89
|
-
export function getModelInfo(model_id: string):
|
|
127
|
+
export function getModelInfo(model_id: string): ModelInfo;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* List all available encoding names.
|
|
131
|
+
*
|
|
132
|
+
* Returns an array of strings: `["cl100k_base", "o200k_base", ...]`
|
|
133
|
+
*/
|
|
134
|
+
export function listEncodings(): any[];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Map a model name to its encoding name without loading the encoding.
|
|
138
|
+
*
|
|
139
|
+
* Returns the encoding name string (e.g. `"o200k_base"`) or `null` for unknown models.
|
|
140
|
+
*/
|
|
141
|
+
export function modelToEncoding(model: string): string | undefined;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* List models filtered by provider name.
|
|
145
|
+
*
|
|
146
|
+
* Provider names: `"OpenAI"`, `"Anthropic"`, `"Google"`, `"Meta"`, `"DeepSeek"`, `"Alibaba"`, `"Mistral"`.
|
|
147
|
+
* Returns an empty array for unknown providers.
|
|
148
|
+
*/
|
|
149
|
+
export function modelsByProvider(provider: string): ModelInfo[];
|
|
90
150
|
|
|
91
151
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
92
152
|
|
|
93
153
|
export interface InitOutput {
|
|
94
154
|
readonly memory: WebAssembly.Memory;
|
|
95
155
|
readonly __wbg_encoding_free: (a: number, b: number) => void;
|
|
156
|
+
readonly __wbg_modelinfo_free: (a: number, b: number) => void;
|
|
157
|
+
readonly allModels: () => [number, number];
|
|
96
158
|
readonly encodingForModel: (a: number, b: number) => [number, number, number];
|
|
97
159
|
readonly encoding_count: (a: number, b: number, c: number) => number;
|
|
160
|
+
readonly encoding_countWithSpecialTokens: (a: number, b: number, c: number) => number;
|
|
98
161
|
readonly encoding_decode: (a: number, b: number, c: number) => [number, number];
|
|
99
162
|
readonly encoding_encode: (a: number, b: number, c: number) => [number, number];
|
|
100
163
|
readonly encoding_encodeWithSpecialTokens: (a: number, b: number, c: number) => [number, number];
|
|
101
164
|
readonly encoding_name: (a: number) => [number, number];
|
|
165
|
+
readonly encoding_numSpecialTokens: (a: number) => number;
|
|
166
|
+
readonly encoding_vocabSize: (a: number) => number;
|
|
102
167
|
readonly estimateCost: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
103
168
|
readonly getEncoding: (a: number, b: number) => [number, number, number];
|
|
104
169
|
readonly getModelInfo: (a: number, b: number) => [number, number, number];
|
|
170
|
+
readonly listEncodings: () => [number, number];
|
|
171
|
+
readonly modelToEncoding: (a: number, b: number) => [number, number];
|
|
172
|
+
readonly modelinfo_cachedInputPer1m: (a: number) => [number, number];
|
|
173
|
+
readonly modelinfo_contextWindow: (a: number) => number;
|
|
174
|
+
readonly modelinfo_id: (a: number) => [number, number];
|
|
175
|
+
readonly modelinfo_inputPer1m: (a: number) => number;
|
|
176
|
+
readonly modelinfo_maxOutput: (a: number) => number;
|
|
177
|
+
readonly modelinfo_outputPer1m: (a: number) => number;
|
|
178
|
+
readonly modelinfo_provider: (a: number) => [number, number];
|
|
179
|
+
readonly modelsByProvider: (a: number, b: number) => [number, number];
|
|
180
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
181
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
182
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
105
183
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
106
184
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
107
|
-
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
108
185
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
109
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
110
186
|
readonly __wbindgen_start: () => void;
|
|
111
187
|
}
|
|
112
188
|
|
package/tiktoken_wasm.js
CHANGED
|
@@ -37,6 +37,20 @@ export class Encoding {
|
|
|
37
37
|
const ret = wasm.encoding_count(this.__wbg_ptr, ptr0, len0);
|
|
38
38
|
return ret >>> 0;
|
|
39
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
|
+
}
|
|
40
54
|
/**
|
|
41
55
|
* Decode token ids back to a UTF-8 string.
|
|
42
56
|
*
|
|
@@ -106,9 +120,127 @@ export class Encoding {
|
|
|
106
120
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
107
121
|
}
|
|
108
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
|
+
}
|
|
109
139
|
}
|
|
110
140
|
if (Symbol.dispose) Encoding.prototype[Symbol.dispose] = Encoding.prototype.free;
|
|
111
141
|
|
|
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
|
+
|
|
112
244
|
/**
|
|
113
245
|
* Get an encoding for a model name (e.g. `"gpt-4o"`, `"o3-mini"`, `"llama-4"`, `"deepseek-r1"`).
|
|
114
246
|
*
|
|
@@ -177,14 +309,14 @@ export function getEncoding(name) {
|
|
|
177
309
|
}
|
|
178
310
|
|
|
179
311
|
/**
|
|
180
|
-
* Get model pricing and metadata
|
|
312
|
+
* Get model pricing and metadata.
|
|
181
313
|
*
|
|
182
|
-
* Returns
|
|
183
|
-
* `
|
|
314
|
+
* Returns a typed object with: `id`, `provider`, `inputPer1m`, `outputPer1m`,
|
|
315
|
+
* `cachedInputPer1m`, `contextWindow`, `maxOutput`.
|
|
184
316
|
*
|
|
185
317
|
* Throws `Error` for unknown model ids.
|
|
186
318
|
* @param {string} model_id
|
|
187
|
-
* @returns {
|
|
319
|
+
* @returns {ModelInfo}
|
|
188
320
|
*/
|
|
189
321
|
export function getModelInfo(model_id) {
|
|
190
322
|
const ptr0 = passStringToWasm0(model_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -193,7 +325,56 @@ export function getModelInfo(model_id) {
|
|
|
193
325
|
if (ret[2]) {
|
|
194
326
|
throw takeFromExternrefTable0(ret[1]);
|
|
195
327
|
}
|
|
196
|
-
return
|
|
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;
|
|
197
378
|
}
|
|
198
379
|
|
|
199
380
|
function __wbg_get_imports() {
|
|
@@ -203,29 +384,14 @@ function __wbg_get_imports() {
|
|
|
203
384
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
204
385
|
return ret;
|
|
205
386
|
},
|
|
206
|
-
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
207
|
-
const ret = String(arg1);
|
|
208
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
209
|
-
const len1 = WASM_VECTOR_LEN;
|
|
210
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
211
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
212
|
-
},
|
|
213
387
|
__wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
|
|
214
388
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
215
389
|
},
|
|
216
|
-
|
|
217
|
-
const ret =
|
|
218
|
-
return ret;
|
|
219
|
-
},
|
|
220
|
-
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
221
|
-
arg0[arg1] = arg2;
|
|
222
|
-
},
|
|
223
|
-
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
224
|
-
// Cast intrinsic for `F64 -> Externref`.
|
|
225
|
-
const ret = arg0;
|
|
390
|
+
__wbg_modelinfo_new: function(arg0) {
|
|
391
|
+
const ret = ModelInfo.__wrap(arg0);
|
|
226
392
|
return ret;
|
|
227
393
|
},
|
|
228
|
-
|
|
394
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
229
395
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
230
396
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
231
397
|
return ret;
|
|
@@ -249,6 +415,20 @@ function __wbg_get_imports() {
|
|
|
249
415
|
const EncodingFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
250
416
|
? { register: () => {}, unregister: () => {} }
|
|
251
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
|
+
}
|
|
252
432
|
|
|
253
433
|
function getArrayU32FromWasm0(ptr, len) {
|
|
254
434
|
ptr = ptr >>> 0;
|
package/tiktoken_wasm_bg.wasm
CHANGED
|
Binary file
|