Returns the per-row message objects that llm_fn() / llm_mutate() would
build from prompt or .messages, using the same internal renderer they
use. No request is sent and no file is read or encoded; a "file" role
stays a (glued) path string. Use this to inspect templating, roles, and
multimodal wiring before spending anything.
Usage
llm_render_messages(
.data,
prompt = NULL,
.messages = NULL,
.system_prompt = NULL,
rows = NULL
)Arguments
- .data
A data.frame/tibble whose columns feed the
gluetemplates.- prompt
A single
gluetemplate string (mutually exclusive with.messages).- .messages
A character vector of
gluetemplates, optionally named by role ("system","user","assistant","file"). Unnamed entries default to"user".- .system_prompt
Optional system string, prepended when a row has no
"system"message.- rows
Optional integer vector selecting which rows to render (default: all rows).
Value
A list of length length(rows) (default nrow(.data)). Each element
is either a bare character scalar (prompt only, no system) or a role-named
character vector, identical to what the call path would dispatch.
See also
llm_preview() for a row-level summary with issue flags and the
batch plan; llm_fn(), llm_mutate().
Examples
df <- data.frame(text = c("good", "bad"), stringsAsFactors = FALSE)
llm_render_messages(df, prompt = "Sentiment of: {text}")
llm_render_messages(
df,
.messages = c(system = "Be terse.", user = "Rate: {text}")
)