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
2 changes: 2 additions & 0 deletions pkg-r/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Added `chat_enable_bookmarking()` which adds Shiny bookmarking hooks to save and restore the `{ellmer}` chat client. (#28)

* `chat_app()` now correctly restores the chat client state when refreshing the app, e.g. by reloading the page. (#71)

# shinychat 0.2.0

## New features and improvements
Expand Down
31 changes: 20 additions & 11 deletions pkg-r/R/chat_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
#' Note that these functions will mutate the input `client` object as
#' you chat because your turns will be appended to the history.
#'
#' The app created by `chat_app()` is suitable for interactive use by a single
#' user. For multi-user Shiny apps, use the Shiny module chat functions --
#' `chat_mod_ui()` and `chat_mod_server()` -- and be sure to create a new chat
#' client for each user session.
#'
#' @examples
#' \dontrun{
#' # Interactive in the console ----
#' client <- ellmer::chat_claude()
#' client <- ellmer::chat_anthropic()
#' chat_app(client)
#'
#' # Inside a Shiny app ----
Expand Down Expand Up @@ -42,7 +47,7 @@
#' )
#'
#' server <- function(input, output, session) {
#' claude <- ellmer::chat_claude(model = "claude-3-5-sonnet-latest") # Requires ANTHROPIC_API_KEY
#' claude <- ellmer::chat_anthropic(model = "claude-3-5-sonnet-latest") # Requires ANTHROPIC_API_KEY
#' openai <- ellmer::chat_openai(model = "gpt-4o") # Requires OPENAI_API_KEY
#'
#' chat_mod_server("claude", claude)
Expand All @@ -64,20 +69,24 @@
#' * `chat_mod_server()` includes the shinychat module server logic, and
#' and returns the last turn upon successful chat completion.
#'
#' @describeIn chat_app A simple Shiny app for live chatting.
#' @describeIn chat_app A simple Shiny app for live chatting. Note that this
#' app is suitable for interactive use by a single user; do not use
#' `chat_app()` in a multi-user Shiny app context.
#' @export
chat_app <- function(client, ...) {
check_ellmer_chat(client)

ui <- bslib::page_fillable(
chat_mod_ui("chat", client = client, height = "100%"),
shiny::actionButton(
"close_btn",
label = "",
class = "btn-close",
style = "position: fixed; top: 6px; right: 6px;"
ui <- function(req) {
bslib::page_fillable(
chat_mod_ui("chat", client = client, height = "100%"),
shiny::actionButton(
"close_btn",
label = "",
class = "btn-close",
style = "position: fixed; top: 6px; right: 6px;"
)
)
)
}

server <- function(input, output, session) {
chat_mod_server("chat", client)
Expand Down
13 changes: 10 additions & 3 deletions pkg-r/man/chat_app.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.