Skip to contents

Applies the model's own chat template, as llama.cpp does for a chat request, and returns the resulting text. With prefill, the text ends with the beginning of the assistant's turn, which is the context llm_continue(), llm_next_token(), and llm_score() use.

Usage

llm_render_template(config, messages, prefill = NULL, thinking = NULL)

Arguments

config

An llm_config() for provider "llamacpp".

messages

Chat messages, as in call_llm().

prefill

Text the assistant's turn starts with.

thinking

For reasoning models such as Qwen3. With FALSE the template closes the model's reasoning block before the reply, so prefill opens the answer; with TRUE the turn is left open and prefill is placed where the model would begin, so it can also open the reasoning (for Qwen3, start it with "<think>\n"). By default the configuration's thinking setting, or else FALSE.

Value

One string.

Examples

if (llm_local_ready("smollm2-135m")) {
  cfg <- llm_config("llamacpp", "smollm2-135m")
  llm_local_start("smollm2-135m", threads = 2)
  cat(llm_render_template(cfg, "Name a color.", prefill = "My answer is"))
  llm_local_stop()
}