ai.encode

Returns the tokenized representation of a text.

Syntax

encode(text, options?)

Parameters

Return value

An array of numbers representing the encoded text.

Examples

ai.encode('hello', { model: 'llama2-7b-chat' })
[1, 29871, 22172]

ai.encode("<|im_start|>hello world!", { model: "gpt-4", specials: {"<|im_start|>": 100264 }})
[100264, 15339, 1917, 0]

See also