Learn R Programming

localLLM (version 1.2.0)

apply_gemma_chat_template: Apply Gemma-Compatible Chat Template

Description

Creates a properly formatted chat template for Gemma models, which use <start_of_turn> and <end_of_turn> markers instead of ChatML format. This function addresses compatibility issues with apply_chat_template() when used with Gemma models.

Usage

apply_gemma_chat_template(messages, add_assistant = TRUE)

Value

A character string with properly formatted Gemma chat template

Arguments

messages

A list of message objects, each with 'role' and 'content' fields

add_assistant

Whether to add the assistant turn prefix (default: TRUE)

Examples

Run this code
if (FALSE) {
messages <- list(
  list(role = "system", content = "You are a helpful assistant."),
  list(role = "user", content = "Hello!")
)
formatted <- apply_gemma_chat_template(messages)
}

Run the code above in your browser using DataLab