diff --git a/NAMESPACE b/NAMESPACE index d7a8526..0ef2cbd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(chat) +export(delete_model) export(list_models) export(new_chat) export(pull_model) diff --git a/R/models.r b/R/models.r index 92afbc8..bbe6190 100644 --- a/R/models.r +++ b/R/models.r @@ -1,9 +1,16 @@ -#' Pull a new model or show more information about it +#' Pull, show and delete models #' -#' @param model name of the model. "llama2" by default. +#' @details +#' - `pull_model()`: downloads model +#' - `show_model()`: displays information about a local model +#' - `delete_model()`: deletes local model +#' +#' @param model name of the model. Defaults to "llama2" when `NULL` (except in +#' `delete_model`). #' @inheritParams query #' -#' @return (invisible) a tibble with information about the model +#' @return (invisible) a tibble with information about the model (except in +#' `delete_model`) #' @export #' #' @examples @@ -20,7 +27,7 @@ pull_model <- function(model = NULL, server = NULL) { httr2::request(server) |> httr2::req_url_path_append("/api/pull") |> httr2::req_body_json(list(name = model)) |> - httr2::req_perform_stream(callback = pgrs, buffer_kb = 0.1L) + httr2::req_perform_stream(callback = pgrs, buffer_kb = 0.1) the$str_prgs <- NULL @@ -44,6 +51,22 @@ show_model <- function(model = NULL, server = NULL) { } +#' @rdname pull_model +#' @export +delete_model <- function(model, server = NULL) { + + if (is.null(server)) server <- getOption("rollama_server", default = "http://localhost:11434") + + httr2::request(server) |> + httr2::req_url_path_append("/api/delete") |> + httr2::req_method("DELETE") |> + httr2::req_body_json(list(name = model)) |> + httr2::req_perform() + + cli::cli_progress_message("{cli::col_green(cli::symbol$tick)} {model} removed") +} + + #' List models that are available locally. #' #' @return a tibble of installed models diff --git a/man/pull_model.Rd b/man/pull_model.Rd index 7cc0fba..c7b9d65 100644 --- a/man/pull_model.Rd +++ b/man/pull_model.Rd @@ -3,14 +3,18 @@ \name{pull_model} \alias{pull_model} \alias{show_model} -\title{Pull a new model or show more information about it} +\alias{delete_model} +\title{Pull, show and delete models} \usage{ pull_model(model = NULL, server = NULL) show_model(model = NULL, server = NULL) + +delete_model(model, server = NULL) } \arguments{ -\item{model}{name of the model. "llama2" by default.} +\item{model}{name of the model. Defaults to "llama2" when \code{NULL} (except in +\code{delete_model}).} \item{server}{URL to an Oolama server (not the API). Defaults to "http://localhost:11434".} @@ -19,7 +23,14 @@ show_model(model = NULL, server = NULL) (invisible) a tibble with information about the model } \description{ -Pull a new model or show more information about it +Pull, show and delete models +} +\details{ +\itemize{ +\item \code{pull_model}: downloads model +\item \code{show_model}: displays information about a local model +\item \code{delete_model}: deletes local model +} } \examples{ \dontrun{ diff --git a/man/query.Rd b/man/query.Rd index d2e5fae..5f27ce2 100644 --- a/man/query.Rd +++ b/man/query.Rd @@ -10,7 +10,7 @@ query(q, model = NULL, screen = TRUE, server = NULL) chat(q, model = NULL, screen = TRUE, server = NULL) } \arguments{ -\item{q}{the question.} +\item{q}{the question as a character string or a conversation object.} \item{model}{which model to use. See \url{https://ollama.ai/library} for options. Default is "llama2". Set option(rollama_model = "modelname") to change