Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion pkg-r/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

* Added `chat_append(icon=...)` and `chat_ui(icon_assistant=...)` for customizing the icon that appears next to assistant responses. (#88)

* `chat_mod_server()` now returns a list of reactives for `last_input` and `last_turn`, as well and functions to `update_user_input()` and `clear()` the chat. (#130)
* `chat_mod_server()` now returns a list of reactives for `last_input` and `last_turn`, as well functions to `update_user_input()`, `append()` and `clear()` the chat. (#130, #143, #145)

## Improvements

Expand Down
10 changes: 9 additions & 1 deletion pkg-r/R/chat_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@
#' * `chat_app()` returns a [shiny::shinyApp()] object.
#' * `chat_mod_ui()` returns the UI for a shinychat module.
#' * `chat_mod_server()` includes the shinychat module server logic, and
#' and a list with:
#' returns a list containing:
#'
#' * `last_input`: A reactive value containing the last user input.
#' * `last_turn`: A reactive value containing the last assistant turn.
#' * `update_user_input()`: A function to update the chat input or submit a
#' new user input. Takes the same arguments as [update_chat_user_input()],
#' except for `id` and `session`, which are supplied automatically.
#' * `append()`: A function to append a new message to the chat UI. Takes
#' the same arguments as [chat_append()], except for `id` and `session`,
#' which are supplied automatically.
#' * `clear()`: A function to clear the chat history and the chat UI.
#' `clear()` takes an optional list of `messages` used to initialize the
#' chat after clearing. `messages` should be a list of messages, where
Expand Down Expand Up @@ -224,6 +227,10 @@ chat_mod_server <- function(
)
}

chat_append_mod <- function(response, role = "assistant", icon = NULL) {
chat_append("chat", response, role = role, icon = icon, session = session)
}

client_clear <- function(
messages = NULL,
client_history = c("clear", "set", "append", "keep")
Expand Down Expand Up @@ -271,6 +278,7 @@ chat_mod_server <- function(
last_turn = shiny::reactive(last_turn()),
last_input = shiny::reactive(last_input()),
client = client,
append = chat_append_mod,
update_user_input = chat_update_user_input,
clear = client_clear
)
Expand Down
5 changes: 4 additions & 1 deletion pkg-r/man/chat_app.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.