Skip to main content

Class: LlamaCppTokenizer

Tokenizer for LlamaCpp.

Example

const tokenizer = new LlamaCppTokenizer();

const text = "At first, Nox didn't know what to do with the pup.";

const tokenCount = await countTokens(tokenizer, text);
const tokens = await tokenizer.tokenize(text);
const tokensAndTokenTexts = await tokenizer.tokenizeWithTexts(text);
const reconstructedText = await tokenizer.detokenize(tokens);

Implements

Constructors

constructor

new LlamaCppTokenizer(api?): LlamaCppTokenizer

Parameters

NameType
apiApiConfiguration

Returns

LlamaCppTokenizer

Defined in

packages/modelfusion/src/model-provider/llamacpp/LlamaCppTokenizer.ts:30

Methods

callTokenizeAPI

callTokenizeAPI(text, callOptions?): Promise<{ tokens: number[] }>

Parameters

NameType
textstring
callOptions?FunctionCallOptions

Returns

Promise<{ tokens: number[] }>

Defined in

packages/modelfusion/src/model-provider/llamacpp/LlamaCppTokenizer.ts:34


tokenize

tokenize(text): Promise<number[]>

Asynchronously tokenize the given text into a sequence of numeric tokens.

Parameters

NameTypeDescription
textstringInput text string that needs to be tokenized.

Returns

Promise<number[]>

A promise containing an array of numbers, where each number is a token representing a part or the whole of the input text.

Implementation of

BasicTokenizer.tokenize

Defined in

packages/modelfusion/src/model-provider/llamacpp/LlamaCppTokenizer.ts:65

Properties

api

Readonly api: ApiConfiguration

Defined in

packages/modelfusion/src/model-provider/llamacpp/LlamaCppTokenizer.ts:28