From 5651de792b572bfe43251d031982e534ed36131a Mon Sep 17 00:00:00 2001 From: Hause Lin Date: Wed, 25 Dec 2024 20:54:13 -0500 Subject: [PATCH] Change output of test_connection() to boolean #29 --- R/ollama.R | 26 +++++++++++++------------- R/utils.R | 8 ++++---- man/chat.Rd | 2 +- man/copy.Rd | 2 +- man/create.Rd | 2 +- man/embed.Rd | 2 +- man/embeddings.Rd | 2 +- man/generate.Rd | 2 +- man/list_models.Rd | 2 +- man/model_avail.Rd | 2 +- man/ohelp.Rd | 2 +- man/ps.Rd | 2 +- man/pull.Rd | 2 +- man/push.Rd | 2 +- man/resp_process.Rd | 2 +- man/show.Rd | 2 +- man/test_connection.Rd | 2 +- tests/testthat/test-chat.R | 10 +++++----- tests/testthat/test-copy.R | 2 +- tests/testthat/test-create.R | 2 +- tests/testthat/test-delete.R | 2 +- tests/testthat/test-embed.R | 2 +- tests/testthat/test-embeddings.R | 2 +- tests/testthat/test-generate.R | 6 +++--- tests/testthat/test-list_models.R | 2 +- tests/testthat/test-model_avail.R | 2 +- tests/testthat/test-ps.R | 2 +- tests/testthat/test-pull.R | 2 +- tests/testthat/test-push.R | 2 +- tests/testthat/test-show.R | 2 +- tests/testthat/test-test_connection.R | 13 +++---------- tests/testthat/test-utils.R | 2 +- 32 files changed, 55 insertions(+), 62 deletions(-) diff --git a/R/ollama.R b/R/ollama.R index 3b3414c..e3dd592 100644 --- a/R/ollama.R +++ b/R/ollama.R @@ -75,7 +75,7 @@ create_request <- function(endpoint, host = NULL) { #' @references #' [API documentation](https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-completion) #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' # text prompt #' generate("llama3", "The sky is...", stream = FALSE, output = "df") #' # stream and increase temperature @@ -181,7 +181,7 @@ generate <- function(model, prompt, suffix = "", images = "", system = "", templ #' @return A response in the format specified in the output parameter. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' # one message #' messages <- list( #' list(role = "user", content = "How are you doing?") @@ -296,7 +296,7 @@ chat <- function(model, messages, tools = list(), stream = FALSE, keep_alive = " #' @return A response in the format specified in the output parameter. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' create("mario", "FROM llama3\nSYSTEM You are mario from Super Mario Bros.") #' generate("mario", "who are you?", output = "text") # model should say it's Mario #' delete("mario") # delete the model created above @@ -378,7 +378,7 @@ create <- function(name, modelfile = NULL, stream = FALSE, path = NULL, endpoint #' @return A response in the format specified in the output parameter. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' list_models() # returns dataframe #' list_models("df") # returns dataframe #' list_models("resp") # httr2 response object @@ -425,7 +425,7 @@ list_models <- function(output = c("df", "resp", "jsonlist", "raw", "text"), end #' @return A response in the format specified in the output parameter. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' # show("llama3") # returns jsonlist #' show("llama3", output = "resp") # returns response object show <- function(name, verbose = FALSE, output = c("jsonlist", "resp", "raw"), endpoint = "/api/show", host = NULL) { @@ -472,7 +472,7 @@ show <- function(name, verbose = FALSE, output = c("jsonlist", "resp", "raw"), e #' @return A httr2 response object. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' copy("llama3", "llama3_copy") #' delete("llama3_copy") # delete the model was just got copied copy <- function(source, destination, endpoint = "/api/copy", host = NULL) { @@ -566,7 +566,7 @@ delete <- function(name, endpoint = "/api/delete", host = NULL) { #' @return A httr2 response object. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' pull("llama3") #' pull("all-minilm", stream = FALSE) pull <- function(name, stream = FALSE, insecure = FALSE, endpoint = "/api/pull", host = NULL) { @@ -634,7 +634,7 @@ pull <- function(name, stream = FALSE, insecure = FALSE, endpoint = "/api/pull", #' @return A httr2 response object. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' push("mattw/pygmalion:latest") push <- function(name, insecure = FALSE, stream = FALSE, output = c("resp", "jsonlist", "raw", "text", "df"), endpoint = "/api/push", host = NULL) { @@ -734,7 +734,7 @@ normalize <- function(x) { #' @return A numeric matrix of the embedding. Each column is the embedding for one input. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' embed("nomic-embed-text:latest", "The quick brown fox jumps over the lazy dog.") #' # pass multiple inputs #' embed("nomic-embed-text:latest", c("Good bye", "Bye", "See you.")) @@ -806,7 +806,7 @@ embed <- function(model, input, truncate = TRUE, normalize = TRUE, keep_alive = #' @return A numeric vector of the embedding. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' embeddings("nomic-embed-text:latest", "The quick brown fox jumps over the lazy dog.") #' # pass model options to the model #' embeddings("nomic-embed-text:latest", "Hello!", temperature = 0.1, num_predict = 3) @@ -859,7 +859,7 @@ embeddings <- function(model, prompt, normalize = TRUE, keep_alive = "5m", endpo #' @return A response in the format specified in the output parameter. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' ps("text") ps <- function(output = c("df", "resp", "jsonlist", "raw", "text"), endpoint = "/api/ps", host = NULL) { output <- output[1] @@ -905,7 +905,7 @@ ps <- function(output = c("df", "resp", "jsonlist", "raw", "text"), endpoint = " #' @return Does not return anything. It prints the conversation in the console. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' ohelp(first_prompt = "quit") #' # regular usage: ohelp() ohelp <- function(model = "codegemma:7b", ...) { @@ -954,7 +954,7 @@ ohelp <- function(model = "codegemma:7b", ...) { #' @return A logical value indicating if the model exists. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' model_avail("codegemma:7b") #' model_avail("abc") #' model_avail("llama3") diff --git a/R/utils.R b/R/utils.R index 4274d96..397fb72 100644 --- a/R/utils.R +++ b/R/utils.R @@ -5,7 +5,7 @@ #' #' @param url The URL of the Ollama server. Default is http://localhost:11434 #' -#' @return A httr2 response object. +#' @return Boolean TRUE if the server is running, otherwise FALSE. #' @export #' #' @examples @@ -19,12 +19,12 @@ test_connection <- function(url = "http://localhost:11434") { { resp <- httr2::req_perform(req) message("Ollama local server running") - return(resp) + return(TRUE) }, error = function(e) { message("Ollama local server not running or wrong server.\nDownload and launch Ollama app to run the server. Visit https://ollama.com or https://github.com/ollama/ollama") req$status_code <- 503 - return(req) + return(FALSE) } ) } @@ -81,7 +81,7 @@ stream_handler <- function(x, env, endpoint) { #' @return A data frame, json list, raw or httr2 response object. #' @export #' -#' @examplesIf test_connection()$status_code == 200 +#' @examplesIf test_connection() #' resp <- list_models("resp") #' resp_process(resp, "df") # parse response to dataframe/tibble #' resp_process(resp, "jsonlist") # parse response to list diff --git a/man/chat.Rd b/man/chat.Rd index eb9401f..bca51bf 100644 --- a/man/chat.Rd +++ b/man/chat.Rd @@ -42,7 +42,7 @@ A response in the format specified in the output parameter. Generate a chat completion with message history } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # one message messages <- list( list(role = "user", content = "How are you doing?") diff --git a/man/copy.Rd b/man/copy.Rd index fe402b5..5e24730 100644 --- a/man/copy.Rd +++ b/man/copy.Rd @@ -22,7 +22,7 @@ A httr2 response object. Creates a model with another name from an existing model. } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} copy("llama3", "llama3_copy") delete("llama3_copy") # delete the model was just got copied \dontshow{\}) # examplesIf} diff --git a/man/create.Rd b/man/create.Rd index 6505c9b..c156e51 100644 --- a/man/create.Rd +++ b/man/create.Rd @@ -33,7 +33,7 @@ A response in the format specified in the output parameter. It is recommended to set \code{modelfile} to the content of the Modelfile rather than just set path. } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} create("mario", "FROM llama3\nSYSTEM You are mario from Super Mario Bros.") generate("mario", "who are you?", output = "text") # model should say it's Mario delete("mario") # delete the model created above diff --git a/man/embed.Rd b/man/embed.Rd index 0a5f839..6c2935a 100644 --- a/man/embed.Rd +++ b/man/embed.Rd @@ -39,7 +39,7 @@ A numeric matrix of the embedding. Each column is the embedding for one input. Supercedes the \code{embeddings()} function. } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} embed("nomic-embed-text:latest", "The quick brown fox jumps over the lazy dog.") # pass multiple inputs embed("nomic-embed-text:latest", c("Good bye", "Bye", "See you.")) diff --git a/man/embeddings.Rd b/man/embeddings.Rd index 7d31f44..edb6b81 100644 --- a/man/embeddings.Rd +++ b/man/embeddings.Rd @@ -36,7 +36,7 @@ A numeric vector of the embedding. This function will be deprecated over time and has been superceded by \code{embed()}. See \code{embed()} for more details. } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} embeddings("nomic-embed-text:latest", "The quick brown fox jumps over the lazy dog.") # pass model options to the model embeddings("nomic-embed-text:latest", "Hello!", temperature = 0.1, num_predict = 3) diff --git a/man/generate.Rd b/man/generate.Rd index fd40dc5..77c622c 100644 --- a/man/generate.Rd +++ b/man/generate.Rd @@ -57,7 +57,7 @@ A response in the format specified in the output parameter. Generate a response for a given prompt } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # text prompt generate("llama3", "The sky is...", stream = FALSE, output = "df") # stream and increase temperature diff --git a/man/list_models.Rd b/man/list_models.Rd index 54cd059..9bff4d9 100644 --- a/man/list_models.Rd +++ b/man/list_models.Rd @@ -24,7 +24,7 @@ A response in the format specified in the output parameter. List models that are available locally } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} list_models() # returns dataframe list_models("df") # returns dataframe list_models("resp") # httr2 response object diff --git a/man/model_avail.Rd b/man/model_avail.Rd index a46dfc3..bdfd263 100644 --- a/man/model_avail.Rd +++ b/man/model_avail.Rd @@ -16,7 +16,7 @@ A logical value indicating if the model exists. Check if model is available locally } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} model_avail("codegemma:7b") model_avail("abc") model_avail("llama3") diff --git a/man/ohelp.Rd b/man/ohelp.Rd index 423f551..20d394b 100644 --- a/man/ohelp.Rd +++ b/man/ohelp.Rd @@ -18,7 +18,7 @@ Does not return anything. It prints the conversation in the console. Chat with a model in real-time in R console } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ohelp(first_prompt = "quit") # regular usage: ohelp() \dontshow{\}) # examplesIf} diff --git a/man/ps.Rd b/man/ps.Rd index 9ee1c80..f5fdc7c 100644 --- a/man/ps.Rd +++ b/man/ps.Rd @@ -24,7 +24,7 @@ A response in the format specified in the output parameter. List models that are currently loaded into memory } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ps("text") \dontshow{\}) # examplesIf} } diff --git a/man/pull.Rd b/man/pull.Rd index 0a5e94a..3c766b0 100644 --- a/man/pull.Rd +++ b/man/pull.Rd @@ -30,7 +30,7 @@ A httr2 response object. See https://ollama.com/library for a list of available models. Use the list_models() function to get the list of models already downloaded/installed on your machine. Cancelled pulls are resumed from where they left off, and multiple calls will share the same download progress. } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} pull("llama3") pull("all-minilm", stream = FALSE) \dontshow{\}) # examplesIf} diff --git a/man/push.Rd b/man/push.Rd index 617d4a4..d094dfa 100644 --- a/man/push.Rd +++ b/man/push.Rd @@ -33,7 +33,7 @@ A httr2 response object. Push or upload a model to an Ollama model library. Requires registering for ollama.ai and adding a public key first. } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} push("mattw/pygmalion:latest") \dontshow{\}) # examplesIf} } diff --git a/man/resp_process.Rd b/man/resp_process.Rd index 23f36be..caf8421 100644 --- a/man/resp_process.Rd +++ b/man/resp_process.Rd @@ -18,7 +18,7 @@ A data frame, json list, raw or httr2 response object. Process httr2 response object } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} resp <- list_models("resp") resp_process(resp, "df") # parse response to dataframe/tibble resp_process(resp, "jsonlist") # parse response to list diff --git a/man/show.Rd b/man/show.Rd index 2de653f..e6cb826 100644 --- a/man/show.Rd +++ b/man/show.Rd @@ -30,7 +30,7 @@ A response in the format specified in the output parameter. Model information includes details, modelfile, template, parameters, license, system prompt. } \examples{ -\dontshow{if (test_connection()$status_code == 200) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (test_connection()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # show("llama3") # returns jsonlist show("llama3", output = "resp") # returns response object \dontshow{\}) # examplesIf} diff --git a/man/test_connection.Rd b/man/test_connection.Rd index b3ea52e..bf0740e 100644 --- a/man/test_connection.Rd +++ b/man/test_connection.Rd @@ -10,7 +10,7 @@ test_connection(url = "http://localhost:11434") \item{url}{The URL of the Ollama server. Default is http://localhost:11434} } \value{ -A httr2 response object. +Boolean TRUE if the server is running, otherwise FALSE. } \description{ \code{test_connection()} tests whether the Ollama server is running or not. diff --git a/tests/testthat/test-chat.R b/tests/testthat/test-chat.R index d3a5694..680a717 100644 --- a/tests/testthat/test-chat.R +++ b/tests/testthat/test-chat.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("chat function works with basic input", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") messages <- list( list(role = "user", content = "Tell me a 5-word story.") @@ -56,7 +56,7 @@ test_that("chat function works with basic input", { }) test_that("chat function handles streaming correctly", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") messages <- list( list(role = "user", content = "Count to 5") @@ -70,7 +70,7 @@ test_that("chat function handles streaming correctly", { test_that("chat function handles multiple messages", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") messages <- list( list(role = "user", content = "Hello!"), @@ -86,7 +86,7 @@ test_that("chat function handles multiple messages", { }) test_that("chat function handles additional options", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") messages <- list( list(role = "user", content = "Tell me a very short joke") @@ -102,7 +102,7 @@ test_that("chat function handles additional options", { test_that("chat function handles images in messages", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") skip_if_not(model_avail("benzie/llava-phi-3"), "benzie/llava-phi-3 model not available") images <- c(file.path(system.file("extdata", package = "ollamar"), "image1.png"), diff --git a/tests/testthat/test-copy.R b/tests/testthat/test-copy.R index f09d76f..860d3c9 100644 --- a/tests/testthat/test-copy.R +++ b/tests/testthat/test-copy.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("copy function works with basic input", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") copy("llama3", "llama3-BACKUP") expect_true(model_avail("llama3-BACKUP")) diff --git a/tests/testthat/test-create.R b/tests/testthat/test-create.R index b77f698..fd3ad9b 100644 --- a/tests/testthat/test-create.R +++ b/tests/testthat/test-create.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("create function works with basic input", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") expect_error(create("mario")) expect_error(create("mario", modelfile = "abc", path = "abc")) diff --git a/tests/testthat/test-delete.R b/tests/testthat/test-delete.R index 5ea2abe..3f908cd 100644 --- a/tests/testthat/test-delete.R +++ b/tests/testthat/test-delete.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("delete function works", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") # wrong model expect_invisible(delete("sdafds")) diff --git a/tests/testthat/test-embed.R b/tests/testthat/test-embed.R index 583bf82..cc56e96 100644 --- a/tests/testthat/test-embed.R +++ b/tests/testthat/test-embed.R @@ -4,7 +4,7 @@ library(ollamar) # Note for the following test to work you need to make sure the "all-minilm" model exists locally test_that("embed function works with basic input", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") # one input result <- embed("all-minilm", "hello") diff --git a/tests/testthat/test-embeddings.R b/tests/testthat/test-embeddings.R index 8addb99..a56a85c 100644 --- a/tests/testthat/test-embeddings.R +++ b/tests/testthat/test-embeddings.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("embeddings function works with basic input", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") result <- embeddings("all-minilm", "hello") expect_type(result, "double") diff --git a/tests/testthat/test-generate.R b/tests/testthat/test-generate.R index 11ee9ef..0263830 100644 --- a/tests/testthat/test-generate.R +++ b/tests/testthat/test-generate.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("generate function works with different outputs and resp_process", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") # incorrect output type expect_error(generate("llama3", "The sky is...", output = "abc")) @@ -46,7 +46,7 @@ test_that("generate function works with different outputs and resp_process", { }) test_that("generate function works with additional options", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") expect_s3_class(generate("llama3", "The sky is...", num_predict = 1, temperature = 0), "httr2_response") expect_error(generate("llama3", "The sky is...", abc = 1, sdf = 2)) @@ -55,7 +55,7 @@ test_that("generate function works with additional options", { test_that("generate function works with images", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") skip_if_not(model_avail("benzie/llava-phi-3"), "benzie/llava-phi-3 model not available") image_path <- file.path(system.file("extdata", package = "ollamar"), "image1.png") diff --git a/tests/testthat/test-list_models.R b/tests/testthat/test-list_models.R index 2328730..47ab6cc 100644 --- a/tests/testthat/test-list_models.R +++ b/tests/testthat/test-list_models.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("list_models function works", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") # incorrect output type expect_error(list_models("sdf")) diff --git a/tests/testthat/test-model_avail.R b/tests/testthat/test-model_avail.R index 8249756..f44313d 100644 --- a/tests/testthat/test-model_avail.R +++ b/tests/testthat/test-model_avail.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("model_avail function works with basic input", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") expect_false(model_avail("test")) expect_true(model_avail("llama3")) diff --git a/tests/testthat/test-ps.R b/tests/testthat/test-ps.R index 80283ab..7fa4160 100644 --- a/tests/testthat/test-ps.R +++ b/tests/testthat/test-ps.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("ps list running models endpoint", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") # load models first g1 <- generate('llama3', "tell me a 5 word story") diff --git a/tests/testthat/test-pull.R b/tests/testthat/test-pull.R index f87b6e9..6a79b53 100644 --- a/tests/testthat/test-pull.R +++ b/tests/testthat/test-pull.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("pull function works", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") # streaming is FALSE by default # wrong model diff --git a/tests/testthat/test-push.R b/tests/testthat/test-push.R index 11c0a02..37e4173 100644 --- a/tests/testthat/test-push.R +++ b/tests/testthat/test-push.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("push function works with basic input", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") expect_s3_class(push("mattw/pygmalion:latest"), "httr2_response") diff --git a/tests/testthat/test-show.R b/tests/testthat/test-show.R index e34dc9f..e885d09 100644 --- a/tests/testthat/test-show.R +++ b/tests/testthat/test-show.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("show function works", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") result <- show("llama3", output = "resp") expect_s3_class(result, "httr2_response") diff --git a/tests/testthat/test-test_connection.R b/tests/testthat/test-test_connection.R index 21241cd..731b149 100644 --- a/tests/testthat/test-test_connection.R +++ b/tests/testthat/test-test_connection.R @@ -2,14 +2,7 @@ library(testthat) library(ollamar) test_that("test_connection function works", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") - - result <- test_connection() - expect_s3_class(result, "httr2_response") - expect_equal(result$status_code, 200) - - # wrong url - result <- test_connection(url = "dsfdsf") - expect_s3_class(result, "httr2_request") - expect_equal(result$status_code, 503) + skip_if_not(test_connection(), "Ollama server not available") + expect_equal(test_connection(), TRUE) + expect_equal(test_connection(url = "dsfdsf"), FALSE) }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 5d044af..1061157 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -2,7 +2,7 @@ library(testthat) library(ollamar) test_that("copy function works with basic input", { - skip_if_not(test_connection()$status_code == 200, "Ollama server not available") + skip_if_not(test_connection(), "Ollama server not available") x <- rnorm(5) expect_true(vector_norm(x) == sqrt(sum(x^2)))