Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg-r/tests/testthat/apps/basic/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 17 additions & 1 deletion pkg-r/tests/testthat/helper-fixtures.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading