@@ -167,24 +167,42 @@ chat_ui <- function(
167167# '
168168# ' @examplesIf interactive()
169169# ' library(shiny)
170+ # ' library(coro)
170171# ' library(bslib)
171- # ' library(elmer)
172172# ' library(shinychat)
173- # '
173+ # '
174+ # ' # Dumbest chatbot in the world: ignores user input and chooses
175+ # ' # a random, vague response. For a chatbot, try {elmer}.
176+ # ' fake_chatbot <- async_generator(function(input) {
177+ # ' responses <- c(
178+ # ' "What does that suggest to you?",
179+ # ' "I see.",
180+ # ' "I'm not sure I understand you fully.",
181+ # ' "What do you think?",
182+ # ' "Can you elaborate on that?",
183+ # ' "Interesting question! Let's examine thi... **See more**"
184+ # ' )
185+ # '
186+ # ' await(async_sleep(1))
187+ # ' for (chunk in strsplit(sample(responses, 1), "")[[1]]) {
188+ # ' yield(chunk)
189+ # ' await(async_sleep(0.02))
190+ # ' }
191+ # ' })
192+ # '
174193# ' ui <- page_fillable(
175194# ' chat_ui("chat", fill = TRUE)
176195# ' )
177- # '
178- # ' server <- function(input, output, session) {
179- # ' chat <- chat_openai(model = "gpt-4o")
180196# '
197+ # ' server <- function(input, output, session) {
181198# ' observeEvent(input$chat_user_input, {
182- # ' response <- chat$stream_async (input$chat_user_input)
199+ # ' response <- fake_chatbot (input$chat_user_input)
183200# ' chat_append("chat", response)
184201# ' })
185202# ' }
186- # '
203+ # '
187204# ' shinyApp(ui, server)
205+ # '
188206# ' @export
189207chat_append <- function (id , response , role = c(" assistant" , " user" ), session = getDefaultReactiveDomain()) {
190208 role <- match.arg(role )
0 commit comments