| llama_chat_apply_template | R Documentation |
Formats a conversation using the specified chat template. This is essential for instruct/chat models to work correctly.
llama_chat_apply_template(
messages,
template = NULL,
add_generation_prompt = TRUE
)
messages |
List of messages, each with 'role' and 'content' elements. Roles are typically "system", "user", "assistant". |
template |
Template string (from [llama_chat_template]) or NULL to use default |
add_generation_prompt |
Whether to add the assistant prompt prefix at the end |
A character scalar containing the formatted prompt string, ready
to be passed to llama_generate.
## Not run:
model <- llama_load_model("llama-3.2-instruct.gguf")
tmpl <- llama_chat_template(model)
messages <- list(
list(role = "system", content = "You are a helpful assistant."),
list(role = "user", content = "What is R?")
)
prompt <- llama_chat_apply_template(messages, template = tmpl)
cat(prompt)
ctx <- llama_new_context(model)
response <- llama_generate(ctx, prompt)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.