Class: Openai::Client::Images

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

Constant Summary collapse

CREATE_PATH =
'images/generations'
EDIT_PATH =
'images/edits'
VARIATION_PATH =
'images/variations'

Instance Method Summary collapse

Instance Method Details

#create(body) ⇒ Hash

Public: Makes an API call to create an image given a prompt.

Parameters:

  • body (Hash)

    request body

Returns:

  • (Hash)

    an image



18
19
20
21
22
# File 'lib/openai/client/images.rb', line 18

def create(body)
  Http.new.post(CREATE_PATH, body).body
rescue Faraday::Error
  nil
end

#edit(body) ⇒ Hash

Public: Makes an API call to create an edited or extended image given an original image and a prompt.

Parameters:

  • body (Hash)

    request body

Returns:

  • (Hash)

    an edited or extended image



30
31
32
33
34
# File 'lib/openai/client/images.rb', line 30

def edit(body)
  Http.new.multipart_post(EDIT_PATH, Utils.upload_io(body, %i[image mask], 'png')).body
rescue Faraday::Error
  nil
end

#variations(body) ⇒ Hash

Public: Makes an API call to creates a variation of a given image.

Parameters:

  • body (Hash)

    request body

Returns:

  • (Hash)

    a variation of a given image



42
43
44
45
46
# File 'lib/openai/client/images.rb', line 42

def variations(body)
  Http.new.multipart_post(VARIATION_PATH, Utils.upload_io(body, %i[image], 'png')).body
rescue Faraday::Error
  nil
end