You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Encodes the given text into a sequence of tokens. Use this method when you need to transform a piece of text into the token format that the GPT models can process.
201
201
202
+
The optional `encodeOptions` parameter allows you to specify special token handling (see [special tokens](#special-tokens)).
203
+
202
204
Example:
203
205
204
206
```typescript
@@ -327,7 +329,11 @@ async function processTokens(asyncTokensIterator) {
327
329
## Special tokens
328
330
329
331
There are a few special tokens that are used by the GPT models.
330
-
Not all models support all of these tokens.
332
+
Note that not all models support all of these tokens.
333
+
334
+
By default, **all special tokens are disallowed**.
335
+
336
+
The `encode`, `encodeGenerator` and `countTokens` functions accept an `EncodeOptions` parameter to customize special token handling:
You may also use a special shorthand for either disallowing or allowing all special tokens, by passing in the string `'all'`, e.g. `{ allowedSpecial: 'all' }`.
365
+
358
366
### Custom Disallowed Sets
359
367
360
368
Similarly, you can specify custom sets of disallowed special tokens when encoding text. Pass a `Set`
0 commit comments