Class: OpenAI::Resources::Images

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/images.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Images

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Images.

Parameters:



138
139
140
# File 'lib/openai/resources/images.rb', line 138

def initialize(client:)
  @client = client
end

Instance Method Details

#create_variation(image: , model: nil, n: nil, response_format: nil, size: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse

Some parameter documentations has been truncated, see Models::ImageCreateVariationParams for more details.

Creates a variation of a given image. This endpoint only supports ‘dall-e-2`.

Parameters:

  • image (Pathname, StringIO, IO, String, OpenAI::FilePart)

    The image to use as the basis for the variation(s). Must be a valid PNG file, le

  • model (String, Symbol, OpenAI::Models::ImageModel, nil)

    The model to use for image generation. Only ‘dall-e-2` is supported at this time

  • n (Integer, nil)

    The number of images to generate. Must be between 1 and 10.

  • response_format (Symbol, OpenAI::Models::ImageCreateVariationParams::ResponseFormat, nil)

    The format in which the generated images are returned. Must be one of ‘url` or `

  • size (Symbol, OpenAI::Models::ImageCreateVariationParams::Size, nil)

    The size of the generated images. Must be one of ‘256x256`, `512x512`, or `1024x

  • user (String)

    A unique identifier representing your end-user, which can help OpenAI to monitor

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/openai/resources/images.rb', line 30

def create_variation(params)
  parsed, options = OpenAI::ImageCreateVariationParams.dump_request(params)
  @client.request(
    method: :post,
    path: "images/variations",
    headers: {"content-type" => "multipart/form-data"},
    body: parsed,
    model: OpenAI::ImagesResponse,
    options: options
  )
end

#edit(image: , prompt: , background: nil, mask: nil, model: nil, n: nil, quality: nil, response_format: nil, size: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse

Some parameter documentations has been truncated, see Models::ImageEditParams for more details.

Creates an edited or extended image given one or more source images and a prompt. This endpoint only supports ‘gpt-image-1` and `dall-e-2`.

Parameters:

  • image (Pathname, StringIO, IO, String, OpenAI::FilePart, Array<Pathname, StringIO, IO, String, OpenAI::FilePart>)

    The image(s) to edit. Must be a supported image file or an array of images.

  • prompt (String)

    A text description of the desired image(s). The maximum length is 1000 character

  • background (Symbol, OpenAI::Models::ImageEditParams::Background, nil)

    Allows to set transparency for the background of the generated image(s).

  • mask (Pathname, StringIO, IO, String, OpenAI::FilePart)

    An additional image whose fully transparent areas (e.g. where alpha is zero) ind

  • model (String, Symbol, OpenAI::Models::ImageModel, nil)

    The model to use for image generation. Only ‘dall-e-2` and `gpt-image-1` are sup

  • n (Integer, nil)

    The number of images to generate. Must be between 1 and 10.

  • quality (Symbol, OpenAI::Models::ImageEditParams::Quality, nil)

    The quality of the image that will be generated. ‘high`, `medium` and `low` are

  • response_format (Symbol, OpenAI::Models::ImageEditParams::ResponseFormat, nil)

    The format in which the generated images are returned. Must be one of ‘url` or `

  • size (Symbol, OpenAI::Models::ImageEditParams::Size, nil)

    The size of the generated images. Must be one of ‘1024x1024`, `1536x1024` (lands

  • user (String)

    A unique identifier representing your end-user, which can help OpenAI to monitor

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/openai/resources/images.rb', line 75

def edit(params)
  parsed, options = OpenAI::ImageEditParams.dump_request(params)
  @client.request(
    method: :post,
    path: "images/edits",
    headers: {"content-type" => "multipart/form-data"},
    body: parsed,
    model: OpenAI::ImagesResponse,
    options: options
  )
end

#generate(prompt: , background: nil, model: nil, moderation: nil, n: nil, output_compression: nil, output_format: nil, quality: nil, response_format: nil, size: nil, style: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse

Some parameter documentations has been truncated, see Models::ImageGenerateParams for more details.

Creates an image given a prompt. [Learn more](platform.openai.com/docs/guides/images).

Parameters:

Returns:

See Also:



124
125
126
127
128
129
130
131
132
133
# File 'lib/openai/resources/images.rb', line 124

def generate(params)
  parsed, options = OpenAI::ImageGenerateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "images/generations",
    body: parsed,
    model: OpenAI::ImagesResponse,
    options: options
  )
end