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



16
17
18
19
20
# File 'lib/openai/client/images.rb', line 16

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



28
29
30
31
32
# File 'lib/openai/client/images.rb', line 28

def edit(body)
  Http.new.multipart_post(EDIT_PATH, upload_io(body, %i[image mask])).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



40
41
42
43
44
# File 'lib/openai/client/images.rb', line 40

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