Class: Asimov::ApiV1::Images

Inherits:
Base
  • Object
show all
Defined in:
lib/asimov/api_v1/images.rb

Overview

Class interface for API methods in the “/images” URI subspace.

Instance Method Summary collapse

Methods inherited from Base

#http_delete, #http_get, #http_streamed_download, #initialize, #json_post, #multipart_post

Constructor Details

This class inherits a constructor from Asimov::ApiV1::Base

Instance Method Details

#create(prompt:, parameters: {}) ⇒ Object

Creates an image using the specified prompt.

Parameters:

  • prompt (String)

    the prompt used to create the image

  • parameters (Hash) (defaults to: {})

    additional parameters passed to the API

Raises:



18
19
20
21
22
23
# File 'lib/asimov/api_v1/images.rb', line 18

def create(prompt:, parameters: {})
  raise MissingRequiredParameterError.new(:prompt) unless prompt

  json_post(path: "#{URI_PREFIX}/generations",
            parameters: parameters.merge({ prompt: prompt }))
end

#create_edit(image:, prompt:, parameters: {}) ⇒ Object

Creates edits of the specified image based on the prompt.

Parameters:

  • image (String)

    file name or a File-like object of the base image

  • prompt (String)

    the prompt used to guide the edit

  • parameters (Hash) (defaults to: {})

    additional parameters passed to the API

Raises:



32
33
34
35
36
37
# File 'lib/asimov/api_v1/images.rb', line 32

def create_edit(image:, prompt:, parameters: {})
  raise MissingRequiredParameterError.new(:prompt) unless prompt

  multipart_post(path: "#{URI_PREFIX}/edits",
                 parameters: open_files(parameters.merge({ image: image, prompt: prompt })))
end

#create_variation(image:, parameters: {}) ⇒ Object

Creates variations of the specified image.

Parameters:

  • image (String)

    file name or a File-like object of the base image

  • parameters (Hash) (defaults to: {})

    additional parameters passed to the API

Options Hash (parameters:):

  • :mask (String)

    mask file name or a File-like object



46
47
48
49
# File 'lib/asimov/api_v1/images.rb', line 46

def create_variation(image:, parameters: {})
  multipart_post(path: "#{URI_PREFIX}/variations",
                 parameters: open_files(parameters.merge({ image: image })))
end