Skip to content

Commit

Permalink
Less dry_run
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Mar 30, 2024
1 parent 07de5b0 commit f52efa0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions R/chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
chat <- function(messages, model = "mistral-tiny", dry_run = FALSE, ..., error_call = current_env()) {
check_dots_empty()

req <- req_chat(messages, model = model, error_call = error_call, dry_run = dry_run)
req <- req_chat(messages, model = model, error_call = error_call)
if (is_true(dry_run)) {
return(req)
}
Expand All @@ -31,7 +31,7 @@ print.chat <- function(x, ...) {
invisible(x)
}

req_chat <- function(messages, model = "mistral-tiny", stream = FALSE, dry_run = FALSE, ..., error_call = caller_env()) {
req_chat <- function(messages, model = "mistral-tiny", stream = FALSE, ..., error_call = caller_env()) {
check_dots_empty()
check_scalar_string(model, error_call = error_call)

Expand Down
8 changes: 2 additions & 6 deletions R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
#' @return A character vector with the models available in the Mistral API
#'
#' @examples
#' models(dry_run = TRUE)
#' models()
#'
#' @export
models <- function(error_call = caller_env(), dry_run = FALSE) {
models <- function(error_call = caller_env()) {
req <- request(mistral_base_url) |>
req_url_path_append("v1", "models") |>
authenticate() |>
req_cache(tempdir(),
use_on_error = TRUE,
max_age = 2 * 60 * 60) # 2 hours

if (is_true(dry_run)) {
return(req)
}

req_mistral_perform(req, error_call = error_call) |>
resp_body_json(simplifyVector = TRUE) |>
pluck("data","id")
Expand Down
2 changes: 1 addition & 1 deletion R/stream.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stream <- function(messages, model = "mistral-tiny", dry_run = FALSE, ..., error
check_dots_empty(call = error_call)

messages <- as_messages(messages)
req <- req_chat(messages, model, stream = TRUE, error_call = error_call, dry_run = dry_run)
req <- req_chat(messages, model, stream = TRUE, error_call = error_call)
if (is_true(dry_run)) {
return(req)
}
Expand Down

0 comments on commit f52efa0

Please sign in to comment.