-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9508fff
commit cbd0dd1
Showing
4 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#' Check if Ollama is running | ||
#' | ||
#' @param verbose Display status message? | ||
#' | ||
#' @return A logical value indicating if Ollama is running or not, invisible. | ||
#' | ||
#' @export | ||
#' @examples | ||
#' ollama_is_available() | ||
#' | ||
ollama_is_available <- function(verbose = FALSE) { | ||
request <- ollama_api_url() %>% | ||
httr2::request() | ||
|
||
check_value <- logical(1) | ||
|
||
rlang::try_fetch({ | ||
response <- httr2::req_perform(request) %>% | ||
httr2::resp_body_string() | ||
|
||
if (verbose) cli::cli_alert_success(response) | ||
check_value <- TRUE | ||
|
||
}, error = function(cnd) { | ||
|
||
if(inherits(cnd, "httr2_failure")) { | ||
if (verbose) cli::cli_alert_danger("Couldn't connect to Ollama in {.url {ollama_api_url()}}. Is it running there?") | ||
} else { | ||
if (verbose) cli::cli_alert_danger(cnd) | ||
} | ||
check_value <- FALSE | ||
}) | ||
|
||
invisible(check_value) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.