Skip to content

Commit

Permalink
export ollama_is_available()
Browse files Browse the repository at this point in the history
  • Loading branch information
calderonsamuel committed Dec 20, 2023
1 parent 9508fff commit cbd0dd1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(ollama_copy_model)
export(ollama_delete_model)
export(ollama_get_library)
export(ollama_get_tags)
export(ollama_is_available)
export(ollama_list)
export(ollama_pull_model)
export(ollama_show_model_info)
Expand Down
36 changes: 36 additions & 0 deletions R/ollama_is_available.R
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)
}

17 changes: 0 additions & 17 deletions R/ollama_url.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,3 @@ ollama_set_task <- function(task) {
httr2::req_url_path_append("api") %>%
httr2::req_url_path_append(task)
}

ollama_check_running <- function() {
request <- ollama_api_url() %>%
httr2::request()

rlang::try_fetch({
httr2::req_perform(request) %>%
httr2::resp_body_string()
}, error = function(cnd) {
if(inherits(cnd, "httr2_failure")) {
cli::cli_abort("Couldn't connect to Ollama in {.url {ollama_api_url()}}. Is it running there?", parent = cnd)
} else {
cnd
}
})
return(TRUE)
}
21 changes: 21 additions & 0 deletions man/ollama_is_available.Rd

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

0 comments on commit cbd0dd1

Please sign in to comment.