View Source ExOpenAI.Images (ex_openai.ex v1.7.0)
Modules for interacting with the images
group of OpenAI APIs
API Reference: https://platform.openai.com/docs/api-reference/images
Summary
Functions
Creates an image given a prompt.
Creates an edited or extended image given an original image and a prompt.
Creates a variation of a given image.
Functions
@spec create_image(String.t(), base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), user: String.t(), style: :natural | :vivid, size: :"1024x1792" | :"1792x1024" | :"1024x1024" | :"512x512" | :"256x256", response_format: :b64_json | :url, quality: :hd | :standard, n: integer(), model: (:"dall-e-3" | :"dall-e-2") | String.t(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ImagesResponse.t()} | {:error, any()}
Creates an image given a prompt.
Endpoint: https://api.openai.com/v1/images/generations
Method: POST
Docs: https://platform.openai.com/docs/api-reference/images
Required Arguments:
prompt
: A text description of the desired image(s). The maximum length is 1000 characters fordall-e-2
and 4000 characters fordall-e-3
.
Example: A cute baby sea otter
Optional Arguments:
stream_to
: PID or function of where to stream content tomodel
: The model to use for image generation.n
: The number of images to generate. Must be between 1 and 10. Fordall-e-3
, onlyn=1
is supported.
Example: 1
quality
: The quality of the image that will be generated.hd
creates images with finer details and greater consistency across the image. This param is only supported fordall-e-3
.
Example: "standard"
response_format
: The format in which the generated images are returned. Must be one ofurl
orb64_json
. URLs are only valid for 60 minutes after the image has been generated.
Example: "url"
size
: The size of the generated images. Must be one of256x256
,512x512
, or1024x1024
fordall-e-2
. Must be one of1024x1024
,1792x1024
, or1024x1792
fordall-e-3
models.
Example: "1024x1024"
style
: The style of the generated images. Must be one ofvivid
ornatural
. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported fordall-e-3
.
Example: "vivid"
user
: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
Example: "user-1234"
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.base_url
: Which API endpoint to use as base, defaults to https://api.openai.com/v1
@spec create_image_edit(bitstring() | {String.t(), bitstring()}, String.t(), base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), user: String.t(), size: :"1024x1024" | :"512x512" | :"256x256", response_format: :b64_json | :url, n: integer(), model: :"dall-e-2" | String.t(), mask: bitstring() | {String.t(), bitstring()}, stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ImagesResponse.t()} | {:error, any()}
Creates an edited or extended image given an original image and a prompt.
Endpoint: https://api.openai.com/v1/images/edits
Method: POST
Docs: https://platform.openai.com/docs/api-reference/images
Required Arguments:
image
: The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.prompt
: A text description of the desired image(s). The maximum length is 1000 characters.
Example: A cute baby sea otter wearing a beret
Optional Arguments:
stream_to
: PID or function of where to stream content tomask
: An additional image whose fully transparent areas (e.g. where alpha is zero) indicate whereimage
should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions asimage
.model
: The model to use for image generation. Onlydall-e-2
is supported at this time.n
: The number of images to generate. Must be between 1 and 10.
Example: 1
response_format
: The format in which the generated images are returned. Must be one ofurl
orb64_json
. URLs are only valid for 60 minutes after the image has been generated.
Example: "url"
size
: The size of the generated images. Must be one of256x256
,512x512
, or1024x1024
.
Example: "1024x1024"
user
: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
Example: "user-1234"
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.base_url
: Which API endpoint to use as base, defaults to https://api.openai.com/v1
@spec create_image_variation(bitstring() | {String.t(), bitstring()}, base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), user: String.t(), size: :"1024x1024" | :"512x512" | :"256x256", response_format: :b64_json | :url, n: integer(), model: :"dall-e-2" | String.t(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ImagesResponse.t()} | {:error, any()}
Creates a variation of a given image.
Endpoint: https://api.openai.com/v1/images/variations
Method: POST
Docs: https://platform.openai.com/docs/api-reference/images
Required Arguments:
image
: The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
Optional Arguments:
stream_to
: PID or function of where to stream content tomodel
: The model to use for image generation. Onlydall-e-2
is supported at this time.n
: The number of images to generate. Must be between 1 and 10. Fordall-e-3
, onlyn=1
is supported.
Example: 1
response_format
: The format in which the generated images are returned. Must be one ofurl
orb64_json
. URLs are only valid for 60 minutes after the image has been generated.
Example: "url"
size
: The size of the generated images. Must be one of256x256
,512x512
, or1024x1024
.
Example: "1024x1024"
user
: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
Example: "user-1234"
openai_api_key
: OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value.openai_organization_key
: OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value.base_url
: Which API endpoint to use as base, defaults to https://api.openai.com/v1