Skip to content

Commit

Permalink
remove dependencies and update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHWade committed Aug 27, 2024
1 parent 1fbe973 commit 281f346
Show file tree
Hide file tree
Showing 16 changed files with 513 additions and 67 deletions.
2 changes: 0 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ BugReports: https://github.com/MichelNivard/gptstudio/issues
Depends:
R (>= 4.0)
Imports:
assertthat,
bsicons,
bslib (>= 0.8.0),
cli,
colorspace,
curl,
fontawesome,
glue,
grDevices,
htmltools,
Expand Down
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ import(httr2)
import(rlang)
import(shiny)
importFrom(R6,R6Class)
importFrom(assertthat,assert_that)
importFrom(assertthat,is.count)
importFrom(assertthat,is.number)
importFrom(assertthat,is.string)
importFrom(glue,glue)
importFrom(htmltools,div)
importFrom(htmltools,htmlDependency)
Expand Down
53 changes: 28 additions & 25 deletions R/api_skeletons.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,35 @@ new_gpstudio_request_skeleton <- function(url, api_key, model, prompt, history,
}

validate_skeleton <- function(url, api_key, model, prompt, history, stream) {
assert_that(
rlang::is_scalar_character(url),
msg = "URL is not a valid character scalar"
)
assert_that(
rlang::is_scalar_character(api_key) && api_key != "",
msg = "API key is not valid"
)
assert_that(
rlang::is_scalar_character(model) && model != "",
msg = "Model name is not a valid character scalar"
)
assert_that(
rlang::is_scalar_character(prompt),
msg = "Prompt is not a valid list"
)
if (!is_scalar_character(url)) {
cli_abort("{.arg url} is not a valid character scalar.
It is a {.cls {class(url)}}.")
}

# is list or is NULL
assert_that(
rlang::is_list(history) || is.null(history),
msg = "History is not a valid list or NULL"
)
assert_that(
rlang::is_bool(stream),
msg = "Stream is not a valid boolean"
)
if (!is_scalar_character(api_key) || api_key == "") {
cli_abort("{.arg api_key} is not a valid character scalar.
It is a {.cls {class(api_key)}}.")
}

if (!is_scalar_character(model) || model == "") {
cli_abort("{.arg model} is not a valid character scalar.
It is a {.cls {class(model)}}.")
}

if (!is_scalar_character(prompt)) {
cli_abort("{.arg prompt} is not a valid character scalar.
It is a {.cls {class(prompt)}}.")
}

if (!is_list(history) && !is.null(history)) {
cli_abort("{.arg history} is not a valid list or NULL.
It is a {.cls {class(history)}}.")
}

if (!is_scalar_logical(stream)) {
cli_abort("{.arg stream} is not a valid boolean.
It is a {.cls {class(stream)}}.")
}
}

new_gptstudio_request_skeleton_openai <- function(
Expand Down
4 changes: 2 additions & 2 deletions R/app_chat_style.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ style_chat_message <- function(message,
#' @param role The role of the message author
#' @inheritParams gptstudio_run_chat_app
#' @return list
create_ide_matching_colors <- function(role,
create_ide_matching_colors <- function(role = c("user", "assistant"),
ide_colors = get_ide_theme_info()) {
assert_that(role %in% c("user", "assistant"))
arg_match(role)

bg_colors <- if (ide_colors$is_dark) {
list(
Expand Down
1 change: 0 additions & 1 deletion R/gptstudio-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#' @import cli
#' @import rlang
#' @import httr2
#' @importFrom assertthat assert_that is.string is.number is.count
#' @importFrom glue glue
## gptstudio namespace: end
NULL
Expand Down
2 changes: 1 addition & 1 deletion R/mod_chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ mod_chat_server <- function(
style = "position: absolute; right: 10px; top: 50%; transform: translateY(-50%);",
bslib::input_task_button(
id = ns("chat"),
label = icon("fas fa-paper-plane"),
label = bsicons::bs_icon("send"),
label_busy = NULL,
class = "btn-secondary p-2 chat-send-btn"
) %>% bslib::tooltip("Send (click or Enter)")
Expand Down
12 changes: 6 additions & 6 deletions R/mod_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ mod_history_ui <- function(id) {
btn_new_chat <- actionButton(
inputId = ns("new_chat"),
label = "New chat",
icon = shiny::icon("plus"),
icon = icon("plus"),
class = "flex-grow-1 me-2"
)

btn_delete_all <- actionButton(
inputId = ns("delete_all"),
label = fontawesome::fa("trash"),
label = bsicons::bs_icon("trash"),
class = "me-2"
) %>%
bslib::tooltip("Delete all chats")

btn_settings <- actionButton(
inputId = ns("settings"),
label = fontawesome::fa("gear")
label = bsicons::bs_icon("gear")
) %>%
bslib::tooltip("Settings")

Expand Down Expand Up @@ -237,21 +237,21 @@ conversation <- function(
class = "multi-click-input flex-grow-1 text-truncate",
`shiny-input-id` = ns_safe("conversation_id", ns),
value = id,
fontawesome::fa("message"),
bsicons::bs_icon("chat"),
title
) %>%
tooltip_on_hover(title, placement = "right")

edit_btn <- tags$span(
fontawesome::fa("pen-to-square", margin_left = "0.4em"),
bsicons::bs_icon("pencil-square"),
class = "multi-click-input",
`shiny-input-id` = ns_safe("conversation_to_edit", ns),
value = id
) %>%
tooltip_on_hover("Edit title", placement = "left")

delete_btn <- tags$span(
fontawesome::fa("trash-can", margin_left = "0.4em"),
bsicons::bs_icon("trash"),
class = "multi-click-input",
`shiny-input-id` = ns_safe("conversation_to_delete", ns),
value = id
Expand Down
14 changes: 7 additions & 7 deletions R/mod_settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod_settings_ui <- function(id, translator = create_translator()) {
read_docs_label <- tags$span(
"Read R help pages",
bslib::tooltip(
shiny::icon("info-circle"),
bsicons::bs_icon("info-circle"),
"Add help pages of 'package::object' matches for context.
Potentially expensive.
Save as default to effectively change"
Expand All @@ -20,7 +20,7 @@ mod_settings_ui <- function(id, translator = create_translator()) {
multiple = FALSE,
bslib::accordion_panel(
title = "Assistant behavior",
icon = fontawesome::fa("robot"),
icon = bsicons::bs_icon("robot"),
selectInput(
inputId = ns("task"),
label = translator$t("Task"),
Expand Down Expand Up @@ -57,7 +57,7 @@ mod_settings_ui <- function(id, translator = create_translator()) {
),
bslib::accordion_panel(
title = "API service",
icon = fontawesome::fa("server"),
icon = bsicons::bs_icon("server"),
selectInput(
inputId = ns("service"),
label = translator$t("Select API Service"),
Expand Down Expand Up @@ -87,7 +87,7 @@ mod_settings_ui <- function(id, translator = create_translator()) {
),
bslib::accordion_panel(
title = "UI options",
icon = fontawesome::fa("sliders"),
icon = bsicons::bs_icon("sliders"),
selectInput(
inputId = ns("language"),
# label = translator$t("Language"), # TODO: update translator
Expand All @@ -101,21 +101,21 @@ mod_settings_ui <- function(id, translator = create_translator()) {

btn_to_history <- actionButton(
inputId = ns("to_history"),
label = fontawesome::fa("arrow-left-long"),
label = bsicons::bs_icon("arrow-left"),
class = "mb-3"
) %>%
bslib::tooltip("Back to history")

btn_save_as_default <- actionButton(
inputId = ns("save_default"),
label = fontawesome::fa("floppy-disk"),
label = bsicons::bs_icon("floppy"),
class = "mb-3"
) %>%
bslib::tooltip("Save as default")

btn_save_in_session <- actionButton(
inputId = ns("save_session"),
label = fontawesome::fa("bookmark"),
label = bsicons::bs_icon("bookmark"),
class = "mb-3"
) %>%
bslib::tooltip("Save for this session")
Expand Down
2 changes: 1 addition & 1 deletion R/record-audio.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ input_audio_clip <- function(
class = "btn btn-sm btn-secondary dropdown-toggle px-3 py-2",
type = "button",
`data-bs-toggle` = "dropdown",
icon("gear", class = "fw")
bsicons::bs_icon("gear")
),
tags$ul(
class = "dropdown-menu",
Expand Down
2 changes: 1 addition & 1 deletion R/service-openai_api_calls.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ openai_create_chat_completion <-
model = getOption("gptstudio.model"),
openai_api_key = Sys.getenv("OPENAI_API_KEY"),
task = "chat/completions") {
if (is.string(prompt)) {
if (is_string(prompt)) {
prompt <- list(
list(
role = "user",
Expand Down
4 changes: 2 additions & 2 deletions inst/assets/js/copyToClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ function addCopyBtn() {
}

// Create a div element with the copy button and language text
// The svg icon was generated using FontAwesome library via R
// The svg icon was generated using Bootrap library via R
var div = $(`
<div class="d-flex justify-content-between bg-dark" style="border-radius: 5px 5px 0 0">
<p class="px-2 py-1 m-0 text-muted small">${language}</p>
<div>
<button type="button" class="btn action-button btn-secondary btn-sm btn-clipboard shiny-bound-input ml-auto">
<i class="fas fa-copy"></i> Copy
<i class="bi bi-copy"></i> Copy
</button>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion man/create_ide_matching_colors.Rd

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

5 changes: 3 additions & 2 deletions revdep/library.noindex/gptstudio/old/gptstudio/shiny/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ chat_card <- bslib::card(
shiny::actionButton(
width = "100%",
inputId = "chat", label = "Chat",
icon = shiny::icon("robot"), class = "btn-primary"
icon = bsicons::bs_icon("robot"),
class = "btn-primary"
),
shiny::br(), shiny::br(),
shiny::fluidRow(
Expand All @@ -34,7 +35,7 @@ chat_card <- bslib::card(
shiny::actionButton(
width = "100%",
inputId = "clear_history", label = "Clear History",
icon = shiny::icon("eraser")
icon = bsicons::bs_icon("eraser")
),
)
)
Expand Down
55 changes: 55 additions & 0 deletions tests/testthat/_snaps/api_skeletons.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,58 @@
$ extras : list()
- attr(*, "class")= chr [1:2] "gptstudio_request_huggingface" "gptstudio_request_skeleton"

# validate_skeleton throws error for invalid URL

Code
validate_skeleton(url = 123, api_key = "valid_key", model = "test_model",
prompt = "What is R?", history = list(), stream = TRUE)
Condition
Error in `validate_skeleton()`:
! `url` is not a valid character scalar. It is a <numeric>.

# validate_skeleton throws error for empty API key

Code
validate_skeleton(url = "https://api.example.com", api_key = "", model = "test_model",
prompt = "What is R?", history = list(), stream = TRUE)
Condition
Error in `validate_skeleton()`:
! `api_key` is not a valid character scalar. It is a <character>.

# validate_skeleton throws error for empty model

Code
validate_skeleton(url = "https://api.example.com", api_key = "valid_key",
model = "", prompt = "What is R?", history = list(), stream = TRUE)
Condition
Error in `validate_skeleton()`:
! `model` is not a valid character scalar. It is a <character>.

# validate_skeleton throws error for non-character prompt

Code
validate_skeleton(url = "https://api.example.com", api_key = "valid_key",
model = "test_model", prompt = list("not a string"), history = list(),
stream = TRUE)
Condition
Error in `validate_skeleton()`:
! `prompt` is not a valid character scalar. It is a <list>.

# validate_skeleton throws error for invalid history

Code
validate_skeleton(url = "https://api.example.com", api_key = "valid_key",
model = "test_model", prompt = "What is R?", history = "not a list", stream = TRUE)
Condition
Error in `validate_skeleton()`:
! `history` is not a valid list or NULL. It is a <character>.

# validate_skeleton throws error for non-boolean stream

Code
validate_skeleton(url = "https://api.example.com", api_key = "valid_key",
model = "test_model", prompt = "What is R?", history = list(), stream = "not a boolean")
Condition
Error in `validate_skeleton()`:
! `stream` is not a valid boolean. It is a <character>.

Loading

0 comments on commit 281f346

Please sign in to comment.