R/chat-utils.R

Defines functions as_chat is_chat

is_chat <- function(x) {
  inherits(x, "Chat")
}

as_chat <- function(x, error_arg = caller_arg(x), error_call = caller_env()) {
  if (is_chat(x)) {
    x
  } else if (is_string(x)) {
    chat(x)
  } else {
    stop_input_type(
      x,
      c("a string", "a <Chat> object"),
      arg = error_arg,
      call = error_call
    )
  }
}

Try the ellmer package in your browser

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

ellmer documentation built on July 14, 2026, 1:07 a.m.