Skip to content

Commit

Permalink
add a function to check is ollama is running in host
Browse files Browse the repository at this point in the history
  • Loading branch information
calderonsamuel committed Dec 7, 2023
1 parent 6b3d8a4 commit 41d5e11
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions R/ollama_url.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
ollama_api_url <- function() {
Sys.getenv("OLLAMA_HOST", "http://localhost:11434/api")
Sys.getenv("OLLAMA_HOST", "http://localhost:11434")
}

ollama_set_task <- function(task) {
ollama_api_url() %>%
httr2::request() %>%
httr2::request() %>%
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)
}

0 comments on commit 41d5e11

Please sign in to comment.