Skip to content

feat: Add chat_enable_bookmarking(id, client, ..., update_on_input = TRUE, update_on_response = TRUE) #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
92b5419
Update .Rbuildignore
schloerke Feb 20, 2025
dc123e3
bump dev version to 0.1.1.9001
schloerke Feb 20, 2025
254c447
Add ellmer as a suggested package
schloerke Feb 20, 2025
e3ffdd9
white space
schloerke Feb 20, 2025
c115d4c
Init `set_chat_model()` method. Handful of TODOs to clean up
schloerke Feb 20, 2025
a351e36
Use session object directly when possible. Handle when bookmark is fr…
schloerke Feb 21, 2025
0423a49
Rename `set_chat_model()` -> ``set_chat_client()`
schloerke Feb 21, 2025
905de19
Clean up the local env when a session is done; Need to explore using …
schloerke Feb 21, 2025
06e8b03
Use session state to store info
schloerke Feb 24, 2025
3a0494a
Display bookmark store values of `"server"` in examples / docs. Add d…
schloerke Feb 26, 2025
194aa73
Default to `disable` for bookmarkStore value. Error when not enabled
schloerke Feb 26, 2025
1c577b6
If using server-side bookmarking, save the `client` object as is! 🎉
schloerke Feb 26, 2025
748ab2f
`set_chat_client()` -> `chat_bookmark()`
schloerke Feb 26, 2025
db7c855
Rename file to `chat_bookmark.R`
schloerke Feb 26, 2025
d1a9ed6
chat_bookmar.R -> chat_enable_bookmark.R
schloerke Mar 4, 2025
9a8c938
`chat_bookmark()` -> `chat_enable_bookmark()`
schloerke Mar 4, 2025
4da8b0b
Merge branch 'main' into bookmark
schloerke May 6, 2025
811ee4d
rename to chat_enable_bookmarking for consistency
schloerke May 6, 2025
ee86e3a
Use `bookmark_on_input` and `bookmark_on_response` param names
schloerke May 6, 2025
917522c
Merge branch 'bookmark' of https://github.com/posit-dev/shinychat int…
schloerke May 6, 2025
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
^_dev$
^cran-comments\.md$
^CRAN-SUBMISSION$
^_dev$
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Imports:
rlang,
shiny (>= 1.10.0)
Suggests:
ellmer,
testthat (>= 3.0.0)
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(chat_app)
export(chat_append)
export(chat_append_message)
export(chat_clear)
export(chat_enable_bookmarking)
export(chat_mod_server)
export(chat_mod_ui)
export(chat_ui)
Expand Down
9 changes: 6 additions & 3 deletions R/chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ chat_deps <- function() {
#'
#' server <- function(input, output, session) {
#' observeEvent(input$chat_user_input, {
#' # In a real app, this would call out to a chat model or API,
#' # In a real app, this would call out to a chat client or API,
#' # perhaps using the 'ellmer' package.
#' response <- paste0(
#' "You said:\n\n",
Expand All @@ -78,6 +78,7 @@ chat_deps <- function() {
#' "</blockquote>"
#' )
#' chat_append("chat", response)
#' chat_append("chat", stream)
#' })
#' }
#'
Expand Down Expand Up @@ -165,7 +166,7 @@ chat_ui <- function(
#' `chat_async`, and `stream_async` methods, respectively).
#'
#' This function should be called from a Shiny app's server. It is generally
#' used to append the model's response to the chat, while user messages are
#' used to append the client's response to the chat, while user messages are
#' added to the chat UI automatically by the front-end. You'd only need to use
#' `chat_append(role="user")` if you are programmatically generating queries
#' from the server and sending them on behalf of the user, and want them to be
Expand Down Expand Up @@ -334,7 +335,7 @@ chat_append_message <- function(
check_active_session(session)

if (!is.list(msg)) {
rlang::abort("msg must be a named list with 'role' and 'content' fields")
rlang::abort("`msg` must be a named list with 'role' and 'content' fields")
}
if (!isTRUE(msg[["role"]] %in% c("user", "assistant"))) {
warning("Invalid role argument; must be 'user' or 'assistant'")
Expand Down Expand Up @@ -408,6 +409,7 @@ chat_append_stream <- function(
session = getDefaultReactiveDomain()
) {
result <- chat_append_stream_impl(id, stream, role, session)
result <- chat_update_bookmark(id, result, session = session)
# Handle erroneous result...
promises::catch(result, function(reason) {
chat_append_message(
Expand All @@ -424,6 +426,7 @@ chat_append_stream <- function(
session = session
)
})

# ...but also return it, so the caller can also handle it if they want. Note
# that we're not returning the result of `promises::catch`; we want to return
# a rejected promise (so the caller can see the error) that was already
Expand Down
Loading