You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried replicating the example from ShinyConf (allowing LLM to update the front-end) but it returns an error - see attached. I followed the code from the demo and the python template online.
Code below:
library(ellmer)
library(shiny)
library(shinychat)
library(bslib)
ui <- bslib::page_sidebar(
sliderInput("slider", label = "slider input", value = 50, min = 0, max = 100),
sidebar = chat_ui("chat",
messages = "Welcome! Try asking me to <span class='suggestion'>update the slider to 80</span> "
)
)
server <- function(input, output, session){
update_slider <- function(value) {
updateSliderInput(
inputId = "slider",
value = value
)
}
chat <- chat_openai(
model = "gpt-4o-mini",
system_prompt = "You are a helpful assistant in the sidebar of a Shiny app.
You have a tool available to you to update a slider in the main panel of the app."
)
update_slider |>
tool(
"Updates the slider input",
value = type_integer()
) |>
chat$register_tool()
observeEvent(input$chat_user_input, {
stream <- chat$stream_async(input$chat_user_input)
chat_append("chat", stream)
})
}
shinyApp(ui, server)
The text was updated successfully, but these errors were encountered:
Hi @shaunalambe5! It took me a bit to diagnose, but the error is happening because ellmer takes the return value of the tool and sends it back to the LLM. So instead of trying to send the return value of updateSliderInput() (which is somehow an R6 object that ellmer can't serialize), send a string back to the LLM saying that the action was taken:
update_slider<-function(value) {
updateSliderInput(
inputId="slider",
value=value
)
"The value was updated."
}
I tried replicating the example from ShinyConf (allowing LLM to update the front-end) but it returns an error - see attached. I followed the code from the demo and the python template online.
Code below:
The text was updated successfully, but these errors were encountered: