ExLLM.Gemini.Files (ex_llm v0.5.0)

View Source

Google Gemini Files API implementation.

Provides functionality to upload, manage, and delete files that can be used with Gemini models for multimodal generation.

Summary

Functions

Gets metadata for a specific file.

Lists files owned by the requesting project.

Uploads a file to the Gemini API using resumable upload.

Waits for a file to become active (processed).

Types

list_options()

@type list_options() :: [
  page_size: integer(),
  page_token: String.t(),
  config_provider: pid() | atom()
]

upload_options()

@type upload_options() :: [display_name: String.t(), config_provider: pid() | atom()]

wait_options()

@type wait_options() :: [
  timeout: integer(),
  poll_interval: integer(),
  config_provider: pid() | atom()
]

Functions

delete_file(file_name, opts \\ [])

@spec delete_file(String.t(), Keyword.t()) :: :ok | {:error, term()}

Deletes a file.

Parameters

  • file_name - The file name (e.g., "files/abc-123")
  • opts - Options including :config_provider

Examples

:ok = ExLLM.Gemini.Files.delete_file("files/abc-123")

get_file(file_name, opts \\ [])

@spec get_file(String.t(), Keyword.t()) ::
  {:ok, ExLLM.Gemini.Files.File.t()} | {:error, term()}

Gets metadata for a specific file.

Parameters

  • file_name - The file name (e.g., "files/abc-123")
  • opts - Options including :config_provider

Examples

{:ok, file} = ExLLM.Gemini.Files.get_file("files/abc-123")

list_files(opts \\ [])

@spec list_files(list_options()) ::
  {:ok,
   %{files: [ExLLM.Gemini.Files.File.t()], next_page_token: String.t() | nil}}
  | {:error, term()}

Lists files owned by the requesting project.

Parameters

  • opts - Options including :page_size, :page_token, and :config_provider

Examples

{:ok, %{files: files, next_page_token: token}} = ExLLM.Gemini.Files.list_files(page_size: 10)

upload_file(file_path, opts \\ [])

@spec upload_file(String.t(), upload_options()) ::
  {:ok, ExLLM.Gemini.Files.File.t()} | {:error, term()}

Uploads a file to the Gemini API using resumable upload.

Parameters

  • file_path - Path to the file to upload
  • opts - Upload options including :display_name and :config_provider

Examples

{:ok, file} = ExLLM.Gemini.Files.upload_file("/path/to/image.png", display_name: "My Image")

wait_for_file(file_name, opts \\ [])

@spec wait_for_file(String.t(), wait_options()) ::
  {:ok, ExLLM.Gemini.Files.File.t()} | {:error, term()}

Waits for a file to become active (processed).

Parameters

  • file_name - The file name (e.g., "files/abc-123")
  • opts - Options including :timeout, :poll_interval, and :config_provider

Examples

{:ok, file} = ExLLM.Gemini.Files.wait_for_file("files/abc-123", timeout: 30_000)