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 originally opened this in tidyverse/ellmer#169 but think shinychat is better positioned to solve the problem.
In many cases, shinychat users will want to directly hook up the chat UI with the chat instance and keep the history in sync in both. In particular, I'd like to see the step from using elmer alone in scripts to using it in Shiny be much smaller.
I'll repeat from the original issue below:
In script or interactive environments, the elmer's chat$chat() interface is very friendly:
library(elmer)
chat<-elmer::chat_openai(model="gpt-4o")
chat$chat(
"What photographic choices were made here, and why do you think the photographer chose them?",
content_image_file("photo.jpg")
)
chat$chat("Come up with an artsy, pretentious, minimalistic, abstract title for this photo.")
But when combined with Shiny there's at least the minimal boilerplate of hooking up an observer for input${id}_user_input, and the boilerplate picks up when you start doing some server-side interaction with the chat messages. Here's an example app where the above turns are handled via action buttons, but the user can still talk with the model
library(elmer)
library(shiny)
library(shinychat)
ui<-bslib::page_fluid(
chat_ui("chat"),
actionButton("ask_photo", "Ask question with image"),
actionButton("ask_follow_up", "Ask follow up question")
)
server<-function(input, output, session) {
chat<- chat_openai(
model="gpt-4o",
)
observeEvent(input$chat_user_input, {
stream<-chat$stream_async(input$chat_user_input)
chat_append("chat", stream)
})
observeEvent(input$ask_photo, {
turn<- Turn(
"user",
list(
ContentText("What photographic choices were made here, and why do you think the photographer chose them?"),
content_image_file("photo.jpg")
)
)
chat_append_message(
"chat",
list(
role="user",
content=turn@text,
)
)
chat_append(
"chat",
chat$stream_async(!!!turn@contents)
)
})
observeEvent(input$ask_follow_up, {
q<-"Come up with an artsy, pretentious, minimalistic, abstract title for this photo."
chat_append_message("chat", list(role="user", content=q))
chat_append("chat", chat$stream_async(q))
})
}
shinyApp(ui, server)
The text was updated successfully, but these errors were encountered:
I originally opened this in tidyverse/ellmer#169 but think shinychat is better positioned to solve the problem.
In many cases, shinychat users will want to directly hook up the chat UI with the chat instance and keep the history in sync in both. In particular, I'd like to see the step from using elmer alone in scripts to using it in Shiny be much smaller.
I'll repeat from the original issue below:
In script or interactive environments, the elmer's
chat$chat()
interface is very friendly:But when combined with Shiny there's at least the minimal boilerplate of hooking up an observer for
input${id}_user_input
, and the boilerplate picks up when you start doing some server-side interaction with the chat messages. Here's an example app where the above turns are handled via action buttons, but the user can still talk with the modelThe text was updated successfully, but these errors were encountered: