diff --git a/R/ollama.R b/R/ollama.R index 9198e2d..ce24cfb 100644 --- a/R/ollama.R +++ b/R/ollama.R @@ -303,7 +303,8 @@ chat <- function(model, messages, output = c("resp", "jsonlist", "raw", "df", "t #' list_models("raw") list_models <- function(output = c("df", "resp", "jsonlist", "raw", "text"), endpoint = "/api/tags", host = NULL) { - if (!output[1] %in% c("df", "resp", "jsonlist", "raw", "text")) { + output <- output[1] + if (!output %in% c("df", "resp", "jsonlist", "raw", "text")) { stop("Invalid output format specified. Supported formats are 'df', 'resp', 'jsonlist', 'raw', 'text'.") } req <- create_request(endpoint, host) @@ -311,7 +312,7 @@ list_models <- function(output = c("df", "resp", "jsonlist", "raw", "text"), end tryCatch( { resp <- httr2::req_perform(req) - return(resp_process(resp = resp, output = output[1])) + return(resp_process(resp = resp, output = output)) }, error = function(e) { stop(e) diff --git a/R/utils.R b/R/utils.R index 0f676d6..c8d4b5a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -61,11 +61,19 @@ resp_process <- function(resp, output = c("df", "jsonlist", "raw", "resp", "text return(resp) } + endpoints_without_stream <- c("api/tags", "api/delete") # endpoints that do not stream + # process stream resp separately stream <- FALSE headers <- httr2::resp_headers(resp) transfer_encoding <- headers$`Transfer-Encoding` # if response is chunked, then it was a streamed output if (!is.null(transfer_encoding)) stream <- grepl("chunked", transfer_encoding) + for (endpoint in endpoints_without_stream) { + if (grepl(endpoint, resp$url)) { + stream <- FALSE + break + } + } if (stream) { return(resp_process_stream(resp, output)) }