Skip to content

Commit

Permalink
adds function check_model_installed
Browse files Browse the repository at this point in the history
  • Loading branch information
JBGruber committed Apr 21, 2024
1 parent d516857 commit 4d0df78
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(chat)
export(chat_history)
export(check_model_installed)
export(copy_model)
export(create_model)
export(delete_model)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# rollama 0.1.0

* adds function `check_model_installed`

# rollama 0.0.3

* add option to query several models at once
Expand Down
30 changes: 30 additions & 0 deletions R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,33 @@ screen_answer <- function(x, model = NULL) {
# "{i}" instead of i stops glue from evaluating code inside the answer
for (i in pars) cli::cli_text("{i}")
}


#' Check if one or several models are installed on the server
#'
#' @param model names of one or several models as character vector.
#' @param auto_pull if FALSE, the default, asks before downloading models.
#' @inheritParams query
#'
#' @return invisible TRUE/FALSE
#' @export
check_model_installed <- function(model, auto_pull = FALSE, server = NULL) {
models_df <- list_models(server = server)
model <- setdiff(model, models_df$name)
model_wo_vers <- gsub(":.*", "", models_df$name)
model <- setdiff(model, model_wo_vers)
if (length(model) > 0L && !auto_pull) {
cli::cli_alert_info("Model{?s} {model} not installed. Would you like to download {?it/them}?")
if (interactive()) auto_pull <- askYesNo("")
if (!auto_pull) {
cli::cli_alert_danger("Model{?s} {model} not installed.")
invisible(FALSE)
}
}
if (auto_pull) {
for (m in model) {
pull_model(m, server = server)
}
}
invisible(TRUE)
}
22 changes: 22 additions & 0 deletions man/check_model_installed.Rd

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

0 comments on commit 4d0df78

Please sign in to comment.