diff --git a/R/app_config.R b/R/app_config.R index 48d3d992..7f889a52 100644 --- a/R/app_config.R +++ b/R/app_config.R @@ -6,7 +6,8 @@ save_user_config <- function(code_style, model, custom_prompt, stream, - read_docs) { + read_docs, + audio_input) { if (is.null(custom_prompt)) custom_prompt <- "" config <- data.frame( @@ -18,7 +19,8 @@ save_user_config <- function(code_style, model, custom_prompt, stream, - read_docs + read_docs, + audio_input ) user_config_path <- tools::R_user_dir("gptstudio", which = "config") user_config <- file.path(user_config_path, "config.yml") @@ -40,7 +42,8 @@ set_user_options <- function(config) { gptstudio.custom_prompt = config$custom_prompt, gptstudio.stream = config$stream, # added in v.3.1+ dev version - gptstudio.read_docs = config$read_docs + gptstudio.read_docs = config$read_docs, + gptstudio.audio_input = config$audio_input ) options(op_gptstudio) invisible() diff --git a/R/mod_chat.R b/R/mod_chat.R index aa8301eb..c0e14d90 100644 --- a/R/mod_chat.R +++ b/R/mod_chat.R @@ -29,27 +29,7 @@ mod_chat_ui <- function(id, translator = create_translator()) { style = css( "width" = "100%" ), - div( - text_area_input_wrapper( - inputId = ns("chat_input"), - label = NULL, - width = "100%", - placeholder = translator$t("Write your prompt here"), - value = "", - resize = "none", - textarea_class = "chat-prompt" - ) - ), - div( - class = "position-absolute top-50 end-0 translate-middle", - bslib::input_task_button( - id = ns("chat"), - label = icon("fas fa-paper-plane"), - label_busy = NULL, - class = "w-100 btn-primary p-1 chat-send-btn" - ) %>% - bslib::tooltip("Send (click or Enter)") - ) + uiOutput(ns("chat_input")) ) ) ) @@ -144,5 +124,46 @@ mod_chat_server <- function(id, updateTextAreaInput(session, "chat_input", value = "") }) %>% bindEvent(input$chat) + + output$chat_input <- renderUI({ + tagList( + fluidRow( + column( + width = 3, + div( + style = "display: flex; align-items: center; height: 100%;", + input_audio_clip("clip", show_mic_settings = FALSE) + ) + ), + column( + width = 9, + div( + style = "display: flex; align-items: center; position: relative; height: 100%;", + div( + style = "flex-grow: 1;", + text_area_input_wrapper( + inputId = "chat_input", + label = NULL, + width = "100%", + value = "", + resize = "none", + textarea_class = "chat-prompt" + ) + ), + div( + style = "position: absolute; right: 10px;", + bslib::input_task_button( + id = "chat", + label = icon("fas fa-paper-plane"), + label_busy = NULL, + class = "w-100 btn-primary p-1 chat-send-btn" + ) %>% + bslib::tooltip("Send (click or Enter)") + ) + ) + ) + ) + ) + }) }) } diff --git a/R/mod_settings.R b/R/mod_settings.R index 30b7a46d..1ec2b581 100644 --- a/R/mod_settings.R +++ b/R/mod_settings.R @@ -77,6 +77,12 @@ mod_settings_ui <- function(id, translator = create_translator()) { label = "Stream Response", value = as.logical(getOption("gptstudio.stream")), width = "100%" + ), + bslib::input_switch( + id = ns("audio_input"), + label = "Audio as Input", + value = as.logical(getOption("gptstudio.audio_input")), + width = "100%" ) ), bslib::accordion_panel( @@ -130,6 +136,7 @@ mod_settings_server <- function(id) { rv$selected_history <- 0L rv$modify_session_settings <- 0L rv$create_new_chat <- 0L + rv$record_input <- 0L observe({ msg <- glue::glue("Fetching models for {input$service} service...") @@ -217,7 +224,8 @@ mod_settings_server <- function(id) { model = input$model, custom_prompt = input$custom_prompt, stream = input$stream, - read_docs = input$read_docs + read_docs = input$read_docs, + audio_input = input$audio_input ) rv$modify_session_settings <- rv$modify_session_settings + 1L @@ -259,6 +267,7 @@ mod_settings_server <- function(id) { rv$service <- input$service %||% getOption("gptstudio.service") rv$stream <- as.logical(input$stream %||% getOption("gptstudio.stream")) rv$custom_prompt <- input$custom_prompt %||% getOption("gptstudio.custom_prompt") + rv$audio_input <- input$audio_input %||% getOption("gptstudio.audio_input") rv$create_new_chat <- rv$create_new_chat + 1L }) %>% diff --git a/R/record-audio.R b/R/record-audio.R index 93024e51..58d7fd17 100644 --- a/R/record-audio.R +++ b/R/record-audio.R @@ -117,7 +117,7 @@ multimodal_dep <- function() { name = "multimodal", version = "0.0.1", package = "shinymedia", - src = "dist", + src = system.file("dist", package = "gptstudio"), script = "index.js", stylesheet = "index.css" ) diff --git a/R/zzz.R b/R/zzz.R index 52797c8c..e2535db7 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -27,7 +27,8 @@ gptstudio.stream = config$stream, # options added after v3.0 will need a safe check because the user's # config file might not have values for new features - gptstudio.read_docs = config$read_docs %||% FALSE + gptstudio.read_docs = config$read_docs %||% FALSE, + gptstudio.audio_input = config$audio_input %||% FALSE ) toset <- !(names(op_gptstudio) %in% names(op)) diff --git a/inst/rstudio/config.yml b/inst/rstudio/config.yml index 529d7efe..412937fd 100644 --- a/inst/rstudio/config.yml +++ b/inst/rstudio/config.yml @@ -7,3 +7,4 @@ model: "gpt-4-turbo-preview" custom_prompt: null stream: true read_docs: false +audio_input: false diff --git a/tests/testthat/_snaps/models.md b/tests/testthat/_snaps/models.md index c44bfd9a..0dbedee2 100644 --- a/tests/testthat/_snaps/models.md +++ b/tests/testthat/_snaps/models.md @@ -15,9 +15,9 @@ Code models Output - [1] "command-r" "command-nightly" "command-r-plus" - [4] "c4ai-aya-23-35b" "command-light-nightly" "c4ai-aya-23-8b" - [7] "command" "command-light" + [1] "c4ai-aya-23-35b" "command-r" "command-nightly" + [4] "command-r-plus" "command-light-nightly" "command" + [7] "command-r-08-2024" "command-light" "c4ai-aya-23-8b" # get_available_models works for google