llama_token_to_piece: Convert a single token ID to its text piece

View source: R/llama.R

llama_token_to_pieceR Documentation

Convert a single token ID to its text piece

Description

Convert a single token ID to its text piece

Usage

llama_token_to_piece(ctx, token, special = FALSE)

Arguments

ctx

A context pointer (llama_context).

token

Integer token ID.

special

Logical. If TRUE, render special tokens (e.g. <bos>).

Value

A character string — the text piece for the token.

Examples

## Not run: 
model <- llama_load_model("model.gguf")
ctx   <- llama_new_context(model)

# Inspect individual tokens from tokenizer output
tokens <- llama_tokenize(ctx, "Hello world")
pieces <- vapply(tokens, function(t) llama_token_to_piece(ctx, t), "")
cat(paste(pieces, collapse = "|"), "\n")

## End(Not run)

llamaR documentation built on May 28, 2026, 1:06 a.m.