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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Imports:
S7 (>= 0.2.0)
Suggests:
base64enc,
bslib,
connectcreds,
curl (>= 6.0.1),
gargle,
Expand All @@ -43,11 +42,13 @@ Suggests:
paws.common,
rmarkdown,
shiny,
shinychat (>= 0.1.1),
shinychat (>= 0.1.1.9001),
testthat (>= 3.0.0),
withr
VignetteBuilder:
knitr
Remotes:
posit-dev/shinychat
Config/Needs/website: tidyverse/tidytemplate, rmarkdown
Config/testthat/edition: 3
Config/testthat/parallel: true
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ellmer (development version)

* `live_browser()` now requires `{shinychat}` v0.2.0 or later which provides
access to the app that powers `live_browser()` via `shinychat::chat_app()`,
as well as Shiny module for easily including a chat interface for an ellmer
`Chat` object in your Shiny apps (#397, @gadenbuie).

* New `chat_mistral()` for models hosted at <https://mistral.ai> (#319).

* `chat_gemini()` can now handle responses that include citation metadata
Expand Down
34 changes: 3 additions & 31 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,8 @@ live_console <- function(chat, quiet = FALSE) {
#' @export
#' @rdname live_console
live_browser <- function(chat, quiet = FALSE) {
check_installed(c("bslib", "shiny", "shinychat"))

messages <- map(chat$get_turns(), function(turn) {
content <- contents_markdown(turn)
if (is.null(content) || identical(content, "")) {
return(NULL)
}
list(role = turn@role, content = content)
})
messages <- compact(messages)

ui <- bslib::page_fillable(
shinychat::chat_ui("chat", height = "100%", messages = messages),
shiny::actionButton(
"close_btn",
label = "",
class = "btn-close",
style = "position: fixed; top: 6px; right: 6px;"
)
)
server <- function(input, output, session) {
shiny::observeEvent(input$chat_user_input, {
stream <- chat$stream_async(input$chat_user_input)
shinychat::chat_append("chat", stream)
})

shiny::observeEvent(input$close_btn, {
shiny::stopApp()
})
}
check_installed("shiny")
check_installed("shinychat", version = "0.1.1.9001")

if (!isTRUE(quiet)) {
cli::cat_boxx(
Expand All @@ -111,7 +83,7 @@ live_browser <- function(chat, quiet = FALSE) {
}

tryCatch(
shiny::runGadget(shiny::shinyApp(ui, server, options = list(quiet = TRUE))),
shiny::runGadget(shinychat::chat_app(chat, options = list(quiet = TRUE))),
interrupt = function(cnd) NULL
)
invisible(chat)
Expand Down