From 796ee088de138c0a258085b2833f4b36122374e9 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Sat, 9 Mar 2024 11:55:30 +0100 Subject: [PATCH] authenticate(dry_run) --- R/authenticate.R | 5 ++--- R/chat.R | 2 +- R/models.R | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/R/authenticate.R b/R/authenticate.R index 36e67a4..568cbf6 100644 --- a/R/authenticate.R +++ b/R/authenticate.R @@ -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/}", @@ -9,4 +9,3 @@ authenticate <- function(request, error_call = caller_env()){ } req_auth_bearer_token(request, key) } - diff --git a/R/chat.R b/R/chat.R index 7198117..ba60d22 100644 --- a/R/chat.R +++ b/R/chat.R @@ -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, diff --git a/R/models.R b/R/models.R index 3105c99..1282b9a 100644 --- a/R/models.R +++ b/R/models.R @@ -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