Skip to content

Commit

Permalink
Add image
Browse files Browse the repository at this point in the history
  • Loading branch information
hauselin committed Jul 28, 2024
1 parent 4fd1fa3 commit 8e905e5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Imports:
base64enc,
crayon,
glue,
httr2,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}











Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file removed inst/extdata/image2.png
Binary file not shown.
21 changes: 21 additions & 0 deletions man/image_encode_base64.Rd

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

0 comments on commit 8e905e5

Please sign in to comment.