Skip to content

[Experimental]

This function uploads a file then waits for Gemini to finish processing it so that you can immediately use it in a prompt. It's experimental because it's currently Gemini specific, and we expect other providers to evolve similar feature in the future.

Uploaded files are automatically deleted after 2 days. Each file must be less than 2 GB and you can upload a total of 20 GB. ellmer doesn't currently provide a way to delete files early; please file an issue if this would be useful for you.

Usage

gemini_upload(
  path,
  base_url = "https://generativelanguage.googleapis.com/v1beta/",
  api_key = NULL,
  mime_type = NULL
)

Arguments

path

Path to a file to upload.

base_url

The base URL to the endpoint; the default uses OpenAI.

api_key

The API key to use for authentication. You generally should not supply this directly, but instead set the GOOGLE_API_KEY environment variable. Or leave it as NULL to use ambient credentials.

mime_type

Optionally, specify the mime type of the file. If not specified, will be guesses from the file extension.

Value

A <ContentUploaded> object that can be passed to $chat().

Examples

if (FALSE) { # \dontrun{
file <- gemini_upload("path/to/file.pdf")

chat <- chat_openai()
chat$chat(file, "Give me a three paragraph summary of this PDF")
} # }