Skip to content

Remove images.R #7

@emitanaka

Description

@emitanaka

Where to put it? Code below.

force_base64_encoding <- function(x) {
  if(!is_base64(x)) x <- base64enc::base64encode(x)
  x
}

is_base64 <- function(x) {
  # https://stackoverflow.com/questions/8571501/how-to-check-whether-a-string-is-base64-encoded-or-not
  grepl("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$", x)
}

#' Describe the input image
#'
#' This requires a multimodal LLM like `llava:7b` to be installed.
#'
#' @param x A url or path to the image.
#' @param model The LLM to use.
emend_describe_image <- function(x,
                               model = emend_get_option("model")) {

  if(model$vendor=="ollama" && !grepl("llava", model$model)) cli::cli_abort("For ollama models, only multimodal models like {.var llava} can process images. Use the argument say {.code model = \"llava:8b\"}.")
  emend_assist(prompt_user("Describe the image.", images = x),
             model = model)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions