diff --git a/pkg-r/tests/testthat/apps/basic/app.R b/pkg-r/tests/testthat/apps/basic/app.R index efa2a9c7f..6a31f7463 100644 --- a/pkg-r/tests/testthat/apps/basic/app.R +++ b/pkg-r/tests/testthat/apps/basic/app.R @@ -24,12 +24,27 @@ dbDisconnect(conn) # Setup database source and QueryChat instance db_conn <- dbConnect(RSQLite::SQLite(), temp_db) +# ellmer 0.5.0 moved model details out of `Provider` and into a new `Model` +# class: `Provider()` no longer takes `model` as its second positional +# argument, and `Chat$new()` now requires a separate `model` argument. `Model` +# doesn't exist before 0.5.0, so branch on its presence to support both. +mock_chat_client <- if ( + exists("Model", where = asNamespace("ellmer"), inherits = FALSE) +) { + MockChat$new( + ellmer::Provider("test", "test"), + model = ellmer::Model(name = "test") + ) +} else { + MockChat$new(ellmer::Provider("test", "test", "test")) +} + # Create QueryChat instance qc <- QueryChat$new( data_source = db_conn, table_name = "iris", greeting = "Welcome to the test app!", - client = MockChat$new(ellmer::Provider("test", "test", "test")) + client = mock_chat_client ) ui <- page_sidebar( diff --git a/pkg-r/tests/testthat/helper-fixtures.R b/pkg-r/tests/testthat/helper-fixtures.R index 5180cf59d..7ce594ce5 100644 --- a/pkg-r/tests/testthat/helper-fixtures.R +++ b/pkg-r/tests/testthat/helper-fixtures.R @@ -173,7 +173,23 @@ mock_ellmer_chat_client <- function( private = private ) - MockChat$new(ellmer::Provider("test", "test", "test")) + new_mock_chat(MockChat) +} + +# ellmer 0.5.0 moved model details out of `Provider` and into a new `Model` +# class: `Provider()` no longer takes `model` as its second positional +# argument, and `Chat$new()` now requires a separate `model` argument. `Model` +# doesn't exist before 0.5.0, so branch on its presence to support both. +new_mock_chat <- function(MockChat, ...) { + if (exists("Model", where = asNamespace("ellmer"), inherits = FALSE)) { + MockChat$new( + ellmer::Provider("test", "test"), + model = ellmer::Model(name = "test"), + ... + ) + } else { + MockChat$new(ellmer::Provider("test", "test", "test"), ...) + } } # shinychat::chat_restore() validates that `client` is an ellmer::Chat() R6