Skip to content

Update chat_enable_bookmarking() to work with latest {ellmer} #79

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

Merged
merged 1 commit into from
Jul 18, 2025

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jul 18, 2025

If you run this app and submit input, you currently get an error -- I believe because the function signature of these ellmer functions changed.

cc @schloerke

library(shiny)
library(bslib)
library(shinychat)

ui <- function(request) {
  page_fillable(chat_ui("chat"))
}

server <- function(input, output, session) {
  chat_client <- ellmer::chat_anthropic(
    system_prompt = "Important: Always respond in a limerick",
    echo = TRUE
  )

  chat_enable_bookmarking("chat", chat_client)

  observeEvent(input$chat_user_input, {
    stream <- chat_client$stream_async(input$chat_user_input)
    chat_append("chat", stream)
  })
}

shinyApp(ui, server, enableBookmarking = "server")
Error in FUN: unused argument (chat = <environment>)

@cpsievert cpsievert merged commit 4f6c09b into main Jul 18, 2025
10 checks passed
@@ -74,8 +73,7 @@ method(client_set_state, S7::new_S3_class(c("Chat", "R6"))) <-

replayed_turns <- lapply(
recorded_turns,
ellmer::contents_replay,
chat = client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to pass in tools = client$get_tools()

(Or something similar.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpsievert @schloerke Did y'all end up resolving this? Or is this currently broken?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like maybe some of the changes in 19a206c (#80) should make it into main?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR #79 gets bookmarking working (without tool calling). Those changes in #80 get bookmarking working with tool calling.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you remember if that changed worked for you as-is? I'm trying to re-apply the patch and the call to chat_enable_bookmarking() in chat_mod_server() leads to

Error in chat_enable_bookmarking("chat", client, session = session) : 
  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")`

And if I add shiny::enableBookmarking("server") to the server function of chat_app() or chat_mod_server(), I'm getting

Error in session$onBookmarked(fun) : 
  onBookmarked() can't be used in a module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh hmm, yea. I don't think I had tested yet with the module approach. I think the way go about it properly would be to first check if bookmarking is enabled?

if (!is.null(shiny::getShinyOption("bookmarkStore"))) {
   chat_enable_bookmarking("chat", client, session = session)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants