These are the building blocks for deploying a commons chat as a Shiny
app; for local development, use commons_app(). Pair commons_server()
with shinychat::page_chat() or shinychat::chat_ui(), passing
theme = commons_theme() so the commons chat assets are on the page.
Arguments
- id
The ID of the chat element; must match the
idof theshinychat::page_chat()orshinychat::chat_ui()on the page.- client
A
commons()agent. In a deployed app, create the agent inside the server function and pass it tocommons_server()so each Shiny session gets its own agent state.- ...
In
commons_server(), arguments passed toshinychat::chat_server(). Incommons_theme(), named Sass variables forwarded toshinychat::page_chat_theme().- preset
A bslib or Bootswatch preset name.
Value
commons_server() returns the shinychat::chat_server() result.
commons_theme() returns a bslib::bs_theme() object.
Details
commons_theme() bundles the commons chat CSS and JavaScript into an
ordinary bslib::bs_theme() (via shinychat::page_chat_theme()), so it
works anywhere a bslib theme does.
Examples
if (FALSE) { # \dontrun{
library(shiny)
library(shinychat)
ui <- page_chat("Assistant", id = "chat", theme = commons_theme())
server <- function(input, output, session) {
# One agent per session, so each user gets their own agent state
agent <- commons(
ellmer::chat_anthropic(),
data_sources = data_source(sales = sales)
)
commons_server("chat", agent)
}
shinyApp(ui, server)
} # }
