Skip to content

Commit

Permalink
authenticate(dry_run)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Mar 9, 2024
1 parent 38081ca commit 796ee08
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions R/authenticate.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
authenticate <- function(request, error_call = caller_env()){
authenticate <- function(request, dry_run = FALSE, error_call = caller_env()){
key <- Sys.getenv("MISTRAL_API_KEY")
if (identical(key, "")) {
if (!is_true(dry_run) && identical(key, "")) {
cli_abort(call = error_call, c(
"Please set the {.code MISTRAL_API_KEY} environment variable",
i = "Get an API key from {.url https://console.mistral.ai/api-keys/}",
Expand All @@ -9,4 +9,3 @@ authenticate <- function(request, error_call = caller_env()){
}
req_auth_bearer_token(request, key)
}

2 changes: 1 addition & 1 deletion R/chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ req_chat <- function(text = "What are the top 5 R packages ?", model = "mistral-
}
request(mistral_base_url) |>
req_url_path_append("v1", "chat", "completions") |>
authenticate(error_call = error_call) |>
authenticate(error_call = error_call, dry_run = dry_run) |>
req_body_json(
list(
model = model,
Expand Down
2 changes: 1 addition & 1 deletion R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
models <- function(error_call = caller_env(), dry_run = FALSE) {
req <- request(mistral_base_url) |>
req_url_path_append("v1", "models") |>
authenticate(error_call = call) |>
authenticate(error_call = call, dry_run = dry_run) |>
req_cache(tempdir(),
use_on_error = TRUE,
max_age = 2 * 60 * 60) # 2 hours
Expand Down

0 comments on commit 796ee08

Please sign in to comment.