Skip to content

Commit

Permalink
Merge pull request #83 from mlverse/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
edgararuiz authored Apr 3, 2024
2 parents 8cb448c + b1b4c50 commit 9a96a84
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 51 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
extra-packages: |
any::rcmdcheck
any::shinytest2
needs: check

- uses: r-lib/actions/check-r-package@v2
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
extra-packages: |
any::covr
any::shinytest2
needs: coverage

- name: Test coverage
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: chattr
Title: Integrates LLM's with the RStudio IDE
Version: 0.0.0.9009
Version: 0.0.0.9010
Authors@R: c(
person("Edgar", "Ruiz", , "[email protected]", role = c("aut", "cre")),
person(given = "Posit Software, PBC", role = c("cph", "fnd"))
Expand All @@ -19,7 +19,7 @@ Imports:
processx,
jsonlite,
config,
httr2 (>= 1.0.0.9000),
httr2 (>= 1.0.1),
purrr,
rlang,
bslib,
Expand All @@ -38,6 +38,7 @@ Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0),
shinytest2,
withr
Config/testthat/edition: 3
VignetteBuilder: knitr
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ S3method(app_init_message,ch_openai)
S3method(app_init_message,default)
S3method(ch_submit,ch_llamagpt)
S3method(ch_submit,ch_openai)
S3method(ch_submit,test_backend)
S3method(ch_submit,ch_test_backend)
S3method(ch_test,ch_llamagpt)
S3method(ch_test,ch_openai_chat_completions)
S3method(ch_test,ch_openai_github_copilot_chat)
Expand Down
11 changes: 9 additions & 2 deletions R/app_server.R → R/app-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ app_server <- function(input, output, session) {
style <- app_theme_style()
ch_env$stream_output <- ""
app_add_history(input)
auto_invalidate <- reactiveTimer(100)
is_test <- unlist(options("chattr-shiny-test")) %||% FALSE
if (is_test) {
use_switch("apptest", path_ext_set("test", "yml"))
invalidate_time <- 1000
} else {
invalidate_time <- 100
}
auto_invalidate <- shiny::reactiveTimer(invalidate_time)
session$sendCustomMessage(type = "refocus", message = list(NULL))

insertUI(
Expand All @@ -24,7 +31,7 @@ app_server <- function(input, output, session) {
})

output$provider <- renderText({
defaults <- chattr_defaults()
defaults <- chattr_defaults(type = "chat")
defaults$label
})

Expand Down
2 changes: 1 addition & 1 deletion R/app_theme.R → R/app-theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ app_theme_style <- function(x = NULL) {
} else {
color_bg <- "#fff"
color_fg <- "#000"
color_dark <- TRUE
color_dark <- FALSE
}

if (color_dark) {
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion R/chattr-app.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ chattr_app <- function(viewer = c("viewer", "dialog"),
}
if (!as_job) {
app <- app_interactive(as_job = as_job)
runGadget(app$ui, app$server, viewer = viewer)
if (ide_is_rstudio()) {
runGadget(app$ui, app$server, viewer = viewer)
} else {
shinyApp(app$ui, app$server)
}
} else {
run_file <- tempfile()
writeLines(
Expand Down
7 changes: 6 additions & 1 deletion R/chattr-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ chattr_defaults <- function(type = "default",
env_model <- Sys.getenv("CHATTR_MODEL", unset = NA)
check_files <- NULL
if (!is.na(env_model)) {
check_files <- package_file("configs", path_ext_set(env_model, "yml"))
if (env_model == "test") {
env_folder <- "apptest"
} else {
env_folder <- "configs"
}
check_files <- package_file(env_folder, path_ext_set(env_model, "yml"))
}

# Overrides environment variable if YAML file is present
Expand Down
10 changes: 8 additions & 2 deletions R/chattr-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,18 @@ ch_test.ch_openai_github_copilot_chat <- function(defaults = NULL) {
}

#' @export
ch_submit.test_backend <- function(
ch_submit.ch_test_backend <- function(
defaults,
prompt = NULL,
stream = NULL,
prompt_build = TRUE,
preview = FALSE,
...) {
"test"
if (stream) {
for (i in seq_len(nchar(prompt))) {
cat(substr(prompt, i, i))
Sys.sleep(0.1)
}
}
prompt
}
6 changes: 4 additions & 2 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ reference:
contents:
- chattr_app
- chattr
- title: Defaults
- title: Session defaults
contents: starts_with("chattr_defaults")
- title: Utilities
contents:
- chattr_use
- chattr_test

- title: Integration
contents:
- ch_submit
13 changes: 13 additions & 0 deletions inst/apptest/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
default:
prompt: |
Use the R language, the tidyverse, and tidymodels
provider: test backend
path: ""
label: Test
model: Test model
max_data_files: 0
max_data_frames: 0
include_doc_contents: FALSE
include_history: FALSE
model_arguments:
n_predict: 1000
File renamed without changes.
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/app-server/001.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"input": {
"close": 0,
"options": 0,
"prompt": "",
"submit": 0,
"tabs": null
},
"output": {
"provider": "Test",
"stream": ""
},
"export": {

}
}
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/app-server/002.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"input": {
"close": 0,
"options": 0,
"prompt": "",
"submit": 1,
"tabs": null
},
"output": {
"provider": "Test",
"stream": ""
},
"export": {

}
}
21 changes: 21 additions & 0 deletions tests/testthat/_snaps/app-server/003.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"input": {
"close": 0,
"i_data": "0",
"i_files": "0",
"i_history": false,
"options": 1,
"prompt": "",
"prompt2": "Use the R language, the tidyverse, and tidymodels",
"saved": 0,
"submit": 1,
"tabs": null
},
"output": {
"provider": "Test",
"stream": ""
},
"export": {

}
}
21 changes: 21 additions & 0 deletions tests/testthat/_snaps/app-server/004.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"input": {
"close": 0,
"i_data": "0",
"i_files": "0",
"i_history": false,
"options": 1,
"prompt": "",
"prompt2": "Use the R language, the tidyverse, and tidymodels",
"saved": 1,
"submit": 1,
"tabs": null
},
"output": {
"provider": "Test",
"stream": ""
},
"export": {

}
}
Loading

0 comments on commit 9a96a84

Please sign in to comment.