Skip to content

Commit

Permalink
[wip] audio input option
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHWade committed Aug 23, 2024
1 parent 78c3078 commit f302d96
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 30 deletions.
9 changes: 6 additions & 3 deletions R/app_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand All @@ -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()
Expand Down
63 changes: 42 additions & 21 deletions R/mod_chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
)
)
)
Expand Down Expand Up @@ -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)")
)
)
)
)
)
})
})
}
11 changes: 10 additions & 1 deletion R/mod_settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}) %>%
Expand Down
2 changes: 1 addition & 1 deletion R/record-audio.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
3 changes: 2 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions inst/rstudio/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ model: "gpt-4-turbo-preview"
custom_prompt: null
stream: true
read_docs: false
audio_input: false
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f302d96

Please sign in to comment.