-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
…om server. Remove debug statements Update chat.R
…session state instead!
Talking with This change below ( library(shiny)
library(bslib)
library(shinychat)
ui <- function(...) {
page_fillable(
chat_ui("chat", fill = TRUE)
)
}
server <- function(input, output, session) {
chat_client <- ellmer::chat_ollama(
system_prompt = "Important: Always respond in a limerick",
model = "qwen2.5-coder:1.5b",
echo = TRUE
)
# Let the UI know that shinychat should bookmark the chat_client
shinychat::chat_bookmark("chat", chat_client) # update_on_input = TRUE, update_on_response = TRUE
observeEvent(input$chat_user_input, {
stream_promise <- chat_client$stream_async(input$chat_user_input)
shinychat::chat_append("chat", stream_promise)
})
}
# Enable bookmarking!
shinyApp(ui, server, enableBookmarking = "server") If other features were to be made, they should have their own |
set_chat_model(id, model, ..., bookmark = TRUE)
chat_bookmark(id, client, ..., update_on_input = TRUE, update_on_response = TRUE)
chat_bookmark(id, client, ..., update_on_input = TRUE, update_on_response = TRUE)
chat_bookmark(id, client)
chat_bookmark(id, client)
chat_bookmark(id, client, ..., update_on_input = TRUE, update_on_response = TRUE)
R/chat_bookmark.R
Outdated
# TODO: Q - I feel this should be removed. Since we are only adding hooks, it doesn't matter if it's enabled or not. If the user diables chat, it would be very annoying to receive error messages for code they may not own. | ||
if (bookmark_store == "disable") { | ||
rlang::abort( | ||
paste0( | ||
"Error: Shiny bookmarking is not enabled. ", | ||
"Please enable bookmarking in your Shiny app either by calling ", | ||
"`shiny::enableBookmarking(\"server\")` or by setting the parameter in ", | ||
"`shiny::shinyApp(enableBookmarking = \"server\")`" | ||
) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining question
@wch Looking for a review on the API: These default parameters hide away the multiple calls to Ex equivalent server code: shinychat::chat_bookmark("chat", chat_client, update_on_input = FALSE, update_on_response = FALSE)
observeEvent(input$chat_user_input, {
session$doBookmark()
stream_promise <- chat_client$stream_async(input$chat_user_input)
stream_promise$then(function(stream_value) { session$doBookmark() })
shinychat::chat_append("chat", stream_promise)
}) Final server code: shinychat::chat_bookmark("chat", chat_client)
observeEvent(input$chat_user_input, {
stream_promise <- chat_client$stream_async(input$chat_user_input)
shinychat::chat_append("chat", stream_promise)
}) |
The new API does look better. A few questions:
|
Co-authored-by: Carson Sievert <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once final comment is addressed, thanks!
Co-authored-by: Carson Sievert <[email protected]>
* main: chore(r): Fix readme logo chore: Update new R package link chore: add recommended extensions chore: fix logo chore: Add a README chore: remove unused scripts ci(quartodoc): Builds API docs in CI docs: metadata on index/404 pages docs: Add custom 404 page docs: Remove redirects docs: Fixup redirects ci(pkgdown): Run when `pkgdown.yaml` changes ci(docs): Need `contents: write` permissions ci(quartodoc): Needs read permissions ci(quartodoc): Use `quarto` binary to render quarto in CI ci(verify-js-built): Only check if JS files change ci(quartodoc): Just install all extras here too Reorganize `shinychat` into a monorepo (#56)
Fixes #27
Fixes #55
Reprex app: