Every conversation with a chatbot consists of pairs of user and assistant
turns, corresponding to an HTTP request and response. These turns are
represented by the Turn
object, which contains a list of Contents representing
the individual messages within the turn. These might be text, images, tool
requests (assistant only), or tool responses (user only).
Note that a call to $chat()
and related functions may result in multiple
user-assistant turn cycles. For example, if you have registered tools,
elmer will automatically handle the tool calling loop, which may result in
any number of additional cycles. Learn more about tool calling in
vignette("tool-calling")
.
Arguments
- role
Either "user", "assistant", or "system".
- contents
A list of Content objects.
- json
The serialized JSON corresponding to the underlying data of the turns. Currently only provided for assistant.
This is useful if there's information returned by the provider that elmer doesn't otherwise expose.
- tokens
A numeric vector of length 2 representing the number of input and output tokens (respectively) used in this turn. Currently only recorded for assistant turns.