Skip to content

Commit

Permalink
Merge pull request #77 from mlverse/updates
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
edgararuiz authored Mar 22, 2024
2 parents 0048a01 + f2fab90 commit 0626ab7
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 25 deletions.
5 changes: 5 additions & 0 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ app_server <- function(input, output, session) {
}
})

output$provider <- renderText({
defaults <- chattr_defaults()
defaults$label
})

observe({
auto_invalidate()
error <- r_session_error()
Expand Down
1 change: 1 addition & 0 deletions R/app_theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ app_theme_style <- function(x = NULL) {
out <- list(
color_bg = color_bg,
color_fg = color_fg,
color_bk = color_bk,
color_top = color_top,
color_user = color_user,
ui_submit = style_collapse(ui_submit),
Expand Down
15 changes: 14 additions & 1 deletion R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ app_ui <- function() {
tags$head(
tags$script("
$(document).keyup(function(event) {
if ((event.keyCode == 27)) {
if (event.keyCode == 27) {
$('#close').click();
}});")
),
tags$head(
tags$script("
$(document).keyup(function(event) {
if (event.keyCode == 13) {
if(event.shiftKey) {
$('#submit').click();
}}});")
),
actionButton(
inputId = "close",
label = NULL,
Expand Down Expand Up @@ -66,6 +74,11 @@ app_ui <- function() {
label = NULL,
icon = icon("gear"),
style = style$ui_submit
),
br(),
div(
uiOutput("provider"),
style = paste0("font-size:9px; color:", style$color_bk, ";")
)
) %>%
tagAppendAttributes(style = "width: 15%;"),
Expand Down
6 changes: 5 additions & 1 deletion R/chattr-app.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ chattr_app <- function(viewer = c("viewer", "dialog"),
as_job_port = getOption("shiny.port", 7788),
as_job_host = getOption("shiny.host", "127.0.0.1")) {
td <- chattr_defaults(type = "chat")
show_init <- TRUE
if(interactive() && is.null(td$provider)) {
chattr_use()
td <- chattr_defaults(type = "chat")
show_init <- FALSE
}
if (viewer[1] == "dialog") {
viewer <- dialogViewer(
Expand All @@ -25,7 +27,9 @@ chattr_app <- function(viewer = c("viewer", "dialog"),
} else {
viewer <- paneViewer()
}
app_init_message(td)
if (show_init) {
app_init_message(td)
}
if (!as_job) {
app <- app_interactive(as_job = as_job)
runGadget(app$ui, app$server, viewer = viewer)
Expand Down
2 changes: 2 additions & 0 deletions R/chattr-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#' @param type Entry point to interact with the model. Accepted values: 'notebook',
#' 'chat'
#' @param force Re-process the base and any work space level file defaults
#' @param label Label to display in the Shiny app, and other locations
#' @param ... Additional model arguments that are not standard for all models/backends
#' @inheritParams chattr

Expand All @@ -43,6 +44,7 @@ chattr_defaults <- function(type = "default",
system_msg = NULL,
yaml_file = "chattr.yml",
force = FALSE,
label = NULL,
...
) {
function_args <- c(as.list(environment()), ...)
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ print_provider <- function(x) {
cli_li("{.val0 Provider:} {.val1 {x$provider}}")
cli_li("{.val0 Path/URL:} {.val1 {x$path}}")
cli_li("{.val0 Model:} {.val1 {x$model}}")
cli_li("{.val0 Label:} {.val1 {x$label}}")
}
1 change: 1 addition & 0 deletions inst/configs/copilot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
default:
provider: OpenAI - GitHub Copilot Chat
path: https://api.githubcopilot.com/chat/completions
label: Copilot (GitHub)
include_history: TRUE
max_data_files: 0
max_data_frames: 0
Expand Down
1 change: 1 addition & 0 deletions inst/configs/davinci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default:
{readLines(system.file('prompt/base.txt', package = 'chattr'))}
provider: OpenAI - Completions
path: https://api.openai.com/v1/completions
label: Davinci 3 (OpenAI)
model: text-davinci-003
max_data_files: 0
max_data_frames: 0
Expand Down
1 change: 1 addition & 0 deletions inst/configs/gpt35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ default:
provider: OpenAI - Chat Completions
path: https://api.openai.com/v1/chat/completions
model: gpt-3.5-turbo
label: GPT 3.5 (OpenAI)
max_data_files: 0
max_data_frames: 0
include_doc_contents: FALSE
Expand Down
1 change: 1 addition & 0 deletions inst/configs/gpt4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default:
{readLines(system.file('prompt/base.txt', package = 'chattr'))}
provider: OpenAI - Chat Completions
path: https://api.openai.com/v1/chat/completions
label: GPT 4 (OpenAI)
model: gpt-4
max_data_files: 0
max_data_frames: 0
Expand Down
1 change: 1 addition & 0 deletions inst/configs/llamagpt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ default:
Use the R language, the tidyverse, and tidymodels
provider: LlamaGPT
path: ~/LlamaGPTJ-chat/build/bin/chat
label: GPT4ALL 1.3 (LlamaGPT)
model: ~/ggml-gpt4all-j-v1.3-groovy.bin
max_data_files: 0
max_data_frames: 0
Expand Down
3 changes: 3 additions & 0 deletions man/chattr_defaults.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions tests/testthat/_snaps/app_ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Provider: OpenAI - Chat Completions
* Path/URL: https://api.openai.com/v1/chat/completions
* Model: gpt-3.5-turbo
* Label: GPT 3.5 (OpenAI)

# UI output is as expected

Expand All @@ -30,14 +31,18 @@
[14] " <button id=\"options\" type=\"button\" class=\"btn btn-default action-button\" style=\"font-size: 55%;padding-top: 3px;padding-bottom: 3px;padding-left: 5px;padding-right: 5px;color: #fff;background-color: #f1f6f8;\">"
[15] " <i class=\"fas fa-gear\" role=\"presentation\" aria-label=\"gear icon\"></i>"
[16] " </button>"
[17] " </div>"
[18] " </div>"
[19] " </div>"
[20] " <div style=\"top:52px;left:1%;width:98%;position:absolute;cursor:inherit;\">"
[21] " <div class=\"tabbable\">"
[17] " <br/>"
[18] " <div style=\"font-size:9px; color:#f1f6f8;\">"
[19] " <div id=\"provider\" class=\"shiny-html-output\"></div>"
[20] " </div>"
[21] " </div>"
[22] " </div>"
[23] " </div>"
[24] "</div>"
[24] " <div style=\"top:52px;left:1%;width:98%;position:absolute;cursor:inherit;\">"
[25] " <div class=\"tabbable\">"
[26] " </div>"
[27] " </div>"
[28] "</div>"

# UI modal output is as expected

Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/_snaps/backend-llamagpt.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Provider: LlamaGPT
* Path/URL: ~/LlamaGPTJ-chat/build/bin/chat
* Model: ~/ggml-gpt4all-j-v1.3-groovy.bin
* Label: GPT4ALL 1.3 (LlamaGPT)

# Session management works

Expand All @@ -19,6 +20,7 @@
* Provider: LlamaGPT
* Path/URL: ~/LlamaGPTJ-chat/build/bin/chat
* Model: ~/ggml-gpt4all-j-v1.3-groovy.bin
* Label: GPT4ALL 1.3 (LlamaGPT)
v Model started sucessfully
v Model session closed sucessfully

Expand Down Expand Up @@ -60,4 +62,5 @@
* Provider: OpenAI - Chat Completions
* Path/URL: https://api.openai.com/v1/chat/completions
* Model: gpt-3.5-turbo
* Label: GPT 3.5 (OpenAI)

1 change: 1 addition & 0 deletions tests/testthat/_snaps/backend-openai-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Provider:
* Path/URL:
* Model:
* Label:
! A list of the top 10 files will be sent externally to OpenAI with every request
To avoid this, set the number of files to be sent to 0 using `chattr::chattr_defaults(max_data_files = 0)`
! A list of the top 10 data.frames currently in your R session will be sent externally to OpenAI with every request
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/_snaps/backend-openai.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Provider: OpenAI - Chat Completions
* Path/URL: https://api.openai.com/v1/chat/completions
* Model: gpt-3.5-turbo
* Label: GPT 3.5 (OpenAI)

---

Expand All @@ -17,6 +18,7 @@
* Provider: OpenAI - Chat Completions
* Path/URL: https://api.openai.com/v1/chat/completions
* Model: gpt-3.5-turbo
* Label: GPT 3.5 (OpenAI)

---

Expand All @@ -28,6 +30,7 @@
* Provider: LlamaGPT
* Path/URL: ~/LlamaGPTJ-chat/build/bin/chat
* Model: ~/ggml-gpt4all-j-v1.3-groovy.bin
* Label: GPT4ALL 1.3 (LlamaGPT)

---

Expand All @@ -37,4 +40,5 @@
* Provider: LlamaGPT
* Path/URL: ~/LlamaGPTJ-chat/build/bin/chat
* Model: ~/ggml-gpt4all-j-v1.3-groovy.bin
* Label: GPT4ALL 1.3 (LlamaGPT)

Loading

0 comments on commit 0626ab7

Please sign in to comment.