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

#initialize, #rest_create_w_json_params, #rest_create_w_multipart_params, #rest_delete, #rest_get, #rest_get_streamed_download, #rest_index

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

  rest_create_w_json_params(resource: [RESOURCE, "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
38
39
40
# File 'lib/asimov/api_v1/images.rb', line 32

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

  rest_create_w_multipart_params(resource: [RESOURCE, "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



49
50
51
52
# File 'lib/asimov/api_v1/images.rb', line 49

def create_variation(image:, parameters: {})
  rest_create_w_multipart_params(resource: [RESOURCE, "variations"],
                                 parameters: open_files(parameters.merge({ image: image })))
end