-
Notifications
You must be signed in to change notification settings - Fork 28
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
Added a shiny app example in streaming-async.Rmd using chat_async
#131
base: main
Are you sure you want to change the base?
Conversation
Added shiny app example for chat_async usage
Removed redundant use of `future` library call
vignettes/streaming-async.Rmd
Outdated
library(shinyjs) | ||
|
||
# Initialize chat | ||
chat <- chat_openai( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely should not put the chat object at this scope, should be inside the observeEvent
Bit simpler version? library(shiny)
library(bslib)
library(elmer)
library(promises)
ui <- page_sidebar(
title = "Interactive chat with async",
sidebar = sidebar(
title = "Controls",
useShinyjs(),
textInput("user_query", "Enter query:"),
input_task_button("ask_chat", label = "Ask the chat")
),
card(
card_header("The chat's response"),
uiOutput("chat_response")
)
)
server <- function(input, output) {
output$chat_response <- renderUI({
# Start the chat fresh each time, as the UI is not a multi-turn conversation
chat <- chat_openai(
system_prompt = "You like chatting about star trek, mostly TNG and onwards (not TOS). Answers should be concise and star trek inspired."
)
# Asynchronously get the (Markdown) results and render to HTML
chat$chat_async("Answer this question:", input$user_query) %...>% markdown()
}) |> bindEvent(input$ask_chat)
}
shinyApp(ui = ui, server = server) |
Incorporated changes suggested by @jcheng5 moved chat init to within server function and using the `input_task_button` instead of previous shinyjs.
Great suggestions!, I have updated the PR accordingly. I have also removed the |
Added shiny app example for chat_async usage