This function creates and validates a chat_history
object, ensuring that it matches
the expected format with 'role' and 'content' columns. It has separate methods
for data.frame
and character
inputs and includes a helper function to add a
system prompt to the chat history.
Examples
chat <- "Hi there!" |>
chat_history()
chat
#> role content
#> 1 user Hi there!
chat_from_df <- data.frame(
role = c("user", "assistant"),
content = c("Hi there!", "Hello! How can I help you today?")
) |>
chat_history()
chat_from_df
#> role content
#> 1 user Hi there!
#> 2 assistant Hello! How can I help you today?