R/genai.openai.chat.history.import.R

Defines functions genai.openai.chat.history.import

#' @noRd
genai.openai.chat.history.import = function(genai.openai.object,
                                            new.chat.history) {
  # Imported chat history is a list
  if (is.list(new.chat.history)) {
    expected.format = list(
      role = NA,
      content = NA
    )
    for (message in new.chat.history) {
      if (!identical(names(message), names(expected.format)) ||
          !is.character(message$role) ||
          !is.character(message$content)) {
        stop("Invalid value for new.chat.history. Please make sure the format of the imported chat history is correct.")
      }
    }
    genai.openai.object$chat.history$messages = new.chat.history
  }
  else {
    stop("Invalid new.chat.history. Please make sure it is a list.")
  }
}

Try the GenAI package in your browser

Any scripts or data that you put into this service are public.

GenAI documentation built on May 29, 2024, 11:58 a.m.