tests/testthat/helper-chat.R

MockedChat <- R6::R6Class(
  "MockedChat",
  inherit = Chat,
  public = list(
    i = 0,
    saved_chats = character(),

    initialize = function(saved_chats) {
      self$saved_chats <- saved_chats
    },

    chat = function(...) {
      self$i <- self$i + 1
      self$saved_chats[self$i]
    }
  )
)

mocked_chat <- function(chats) {
  MockedChat$new(saved_chats = chats)
}

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.