SystemOneClient.Images (SystemOneClient v0.3.0)

Copy Markdown View Source

Validation for the images: option.

Images are base64 data URLs (data:image/png;base64,...); build one from bytes with SystemOneClient.image_data_url/2. Only providers whose APIs accept images can take them, and they are checked before any request is sent:

ProviderAcceptedLimits checked locally
:openaiany image/* data URLnone documented
:cloudflarePNG, JPEG, WebPat most 4 images, 4 MiB each and 8 MiB in total, decoded
othersnoreturns {:error, {:unsupported_option, :images, provider}}

Remote http(s) image URLs are rejected for every provider because neither API accepts them.

Summary

Functions

Checks images for provider.

Types

error()

@type error() ::
  :images_not_a_list
  | {:unsupported_option, :images, atom()}
  | {:invalid_image, non_neg_integer(),
     :not_a_data_url
     | :invalid_base64
     | :too_large
     | {:unsupported_type, String.t()}}
  | {:too_many_images, pos_integer(), pos_integer()}
  | {:images_too_large, non_neg_integer(), pos_integer()}

Functions

validate(images, provider)

@spec validate(term(), atom()) :: :ok | {:error, error()}

Checks images for provider.

iex> SystemOneClient.Images.validate(["data:image/png;base64,YWJj"], :openai)
:ok

iex> SystemOneClient.Images.validate(["https://example.com/a.png"], :openai)
{:error, {:invalid_image, 0, :not_a_data_url}}