Skip to contents

This function takes a response object or a chatlog object as input and returns the messages. If the input is a response object, the function extracts and returns the messages from the choices. If the input is a chatlog object, the function returns the messages directly.

Usage

messages(x)

Arguments

x

A response object (the list returned by chat_completion()) or a chatlog object.

Value

A data.frame of the messages: for a response, the message column of its choices (one row per choice, with columns such as role and content); for a chatlog, its role and content messages.

Examples

# Using a response object, here a hand-built one shaped like the parsed
# reply of chat_completion()
response <- list(choices = data.frame(index = 0))
response$choices$message <- data.frame(role = "assistant",
  content = "This is a message.")
messages(response)
#>        role            content
#> 1 assistant This is a message.

# Using a chatlog object
cl <- start_chat(chatlog_id = "demo")
messages(cl)
#>     role                      content
#> 1 system You are a helpful assistant.

if (FALSE) { # \dontrun{
# Using the stored log of a conversation (needs an API key)
chat("Hello, how are you?", chatlog_id = "demo")
messages(get_chatlog("demo"))
} # }