View source: R/transcript_messages.R
| transcript_as_messages | R Documentation |
Renders a shared, speaker-attributed transcript into a message array from
one speaker's point of view, the way a stateful chat is post-trained to read
it: the current speaker's own past turns become assistant messages (their
own voice), and every other speaker's turns become user messages labeled
with the speaker's name. An optional system block (persona, instructions)
leads the array, and an optional instruction (the current question or "your
turn" cue) closes it as a trailing user message. The result is passed
through ensure_alternating_messages() so it is provider-safe.
transcript_as_messages(
transcript,
speaker,
system = NULL,
instruction = NULL,
label = function(id) paste0(id, ": "),
sanitize = TRUE,
ensure_final_user = TRUE
)
transcript |
A data.frame/tibble with character columns |
speaker |
The current speaker's id (matched against |
system |
Optional system text (persona, standing instructions) placed as
the leading |
instruction |
Optional trailing instruction (current question, "your
turn" cue) placed as the final |
label |
A function |
sanitize |
If |
ensure_final_user |
If |
Putting the speaker's own turns in the assistant role gives the model a
structural handle on "what I already said", which reduces self-repetition in
multi-agent conversations relative to flattening the whole transcript into one
user block. Other speakers' text stays in user turns (never assistant),
which preserves the trust boundary and is sanitized against forged role
headers.
A list of message objects (list(role=, content=)) suitable for
call_llm(), guaranteed alternating and user-leading after any system.
ensure_alternating_messages(), call_llm()
tx <- data.frame(
speaker = c("Ana", "Ben", "Cy"),
text = c("I think we ban it.", "Too costly for renters.", "Phase it in."),
stringsAsFactors = FALSE
)
# From Ben's perspective: his line is assistant, Ana's and Cy's are user.
transcript_as_messages(tx, speaker = "Ben",
system = "You are Ben, a renter.",
instruction = "Your turn, Ben.")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.