diff --git a/DESCRIPTION b/DESCRIPTION index d06837c..4090083 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,6 +15,7 @@ Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 Imports: + base64enc, crayon, glue, httr2, diff --git a/NAMESPACE b/NAMESPACE index b4e5c1c..1db4b1b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(delete_message) export(embed) export(embeddings) export(generate) +export(image_encode_base64) export(insert_message) export(list_models) export(prepend_message) diff --git a/R/utils.R b/R/utils.R index 06d275b..fb89d5b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -180,6 +180,28 @@ resp_process_stream <- function(resp, output) { +#' Read image file and encode it to base64. +#' +#' @param image_path The path to the image file. +#' +#' @return A base64 encoded string. +#' @export +#' +#' @examples +#' image_path <- file.path(system.file('extdata', package = "ollamar"), "image1.png") +#' image_encode_base64(image_path) +image_encode_base64 <- function(image_path) { + img_raw <- readBin(image_path, "raw", file.info(image_path)$size) + return(base64enc::base64encode(img_raw)) +} + + + + + + + + diff --git a/_pkgdown.yml b/_pkgdown.yml index e6ace5c..ff2af29 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -29,6 +29,7 @@ reference: desc: Functions that are useful for working with the Ollama API contents: - resp_process + - image_encode_base64 - create_message - append_message - prepend_message diff --git a/inst/extdata/image2.png b/inst/extdata/image2.png deleted file mode 100644 index aeb3bd5..0000000 Binary files a/inst/extdata/image2.png and /dev/null differ diff --git a/man/image_encode_base64.Rd b/man/image_encode_base64.Rd new file mode 100644 index 0000000..2415b0d --- /dev/null +++ b/man/image_encode_base64.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{image_encode_base64} +\alias{image_encode_base64} +\title{Read image file and encode it to base64.} +\usage{ +image_encode_base64(image_path) +} +\arguments{ +\item{image_path}{The path to the image file.} +} +\value{ +A base64 encoded string. +} +\description{ +Read image file and encode it to base64. +} +\examples{ +image_path <- file.path(system.file('extdata', package = "ollamar"), "image1.png") +image_encode_base64(image_path) +}