diff --git a/inst/retriever/app.R b/inst/retriever/app.R index b45afd3..953f190 100644 --- a/inst/retriever/app.R +++ b/inst/retriever/app.R @@ -1,12 +1,10 @@ rlang::check_installed( - c("shiny", "bsicons", "cli", "glue", "gptstudio", "gpttools", "waiter") + c("shiny", "bslib", "bsicons", "cli", "glue", "gptstudio", "gpttools", "waiter") ) library(gpttools) library(gptstudio) -rlang::check_installed(c("bslib", "bsicons")) - window_height_ui <- function(id) { ns <- shiny::NS(id) namespaced_id <- ns("window_height") @@ -37,6 +35,15 @@ window_height_server <- function(id) { }) } +make_chat_history <- function(chats) { + purrr::discard(chats, \(x) x$role == "system") |> + purrr::map(\(x) { + list(shiny::strong(stringr::str_to_title(x$role)), + shiny::markdown(x$content)) + }) |> + purrr::list_flatten() +} + indices <- gpttools::list_index() |> tools::file_path_sans_ext() ui <- bslib::page_fluid( @@ -73,7 +80,7 @@ ui <- bslib::page_fluid( "Preferences", icon = bsicons::bs_icon("gear-wide-connected"), shiny::selectInput("model", "Model", - choices = c("gpt-3.5-turbo", "gpt-4") + choices = c("gpt-3.5-turbo", "gpt-4") ), shiny::radioButtons( "save_history", "Save & Use History", @@ -166,19 +173,19 @@ server <- function(input, output, session) { ) ) ) - r$all_chats_formatted <- gptstudio:::prepare_chat_history(r$all_chats) + r$all_chats_formatted <- make_chat_history(r$all_chats) waiter::waiter_hide() shiny::updateTextAreaInput(session, "chat_input", value = "") }) |> shiny::bindEvent(input$chat) output$all_chats_box <- renderUI({ + cli::cli_inform("height: {height()}") shiny::req(length(r$context_links) > 0) bslib::card( height = height() - 300, bslib::card_header("Chat History", class = "bg-primary"), bslib::card_body( - fill = FALSE, r$all_chats_formatted, shiny::markdown("**Sources**"), shiny::markdown(paste0("* ", unique(r$context_links), collapse = "\n"))