Class: OpenApiOpenAIClient::ImagesApi

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_openai/api/images_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ ImagesApi

Returns a new instance of ImagesApi.



19
20
21
# File 'lib/openapi_openai/api/images_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/openapi_openai/api/images_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#create_image(create_image_request, opts = {}) ⇒ ImagesResponse

Creates an image given a prompt.

Parameters:

  • create_image_request (CreateImageRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



26
27
28
29
# File 'lib/openapi_openai/api/images_api.rb', line 26

def create_image(create_image_request, opts = {})
  data, _status_code, _headers = create_image_with_http_info(create_image_request, opts)
  data
end

#create_image_edit(image, prompt, opts = {}) ⇒ ImagesResponse

Creates an edited or extended image given an original image and a prompt.

Parameters:

  • image (File)

    The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.

  • prompt (String)

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

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

    the optional parameters

Options Hash (opts):

  • :mask (File)

    An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`.

  • :model (CreateImageEditRequestModel)
  • :n (Integer)

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

  • :size (String)

    The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. (default to ‘1024x1024’)

  • :response_format (String)

    The format in which the generated images are returned. Must be one of `url` or `b64_json`. URLs are only valid for 60 minutes after the image has been generated. (default to ‘url’)

  • :user (String)

    A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).

Returns:



99
100
101
102
# File 'lib/openapi_openai/api/images_api.rb', line 99

def create_image_edit(image, prompt, opts = {})
  data, _status_code, _headers = create_image_edit_with_http_info(image, prompt, opts)
  data
end

#create_image_edit_with_http_info(image, prompt, opts = {}) ⇒ Array<(ImagesResponse, Integer, Hash)>

Creates an edited or extended image given an original image and a prompt.

Parameters:

  • image (File)

    The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.

  • prompt (String)

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

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

    the optional parameters

Options Hash (opts):

  • :mask (File)

    An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where &#x60;image&#x60; should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as &#x60;image&#x60;.

  • :model (CreateImageEditRequestModel)
  • :n (Integer)

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

  • :size (String)

    The size of the generated images. Must be one of &#x60;256x256&#x60;, &#x60;512x512&#x60;, or &#x60;1024x1024&#x60;. (default to ‘1024x1024’)

  • :response_format (String)

    The format in which the generated images are returned. Must be one of &#x60;url&#x60; or &#x60;b64_json&#x60;. URLs are only valid for 60 minutes after the image has been generated. (default to ‘url’)

  • :user (String)

    A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).

Returns:

  • (Array<(ImagesResponse, Integer, Hash)>)

    ImagesResponse data, response status code and response headers



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/openapi_openai/api/images_api.rb', line 115

def create_image_edit_with_http_info(image, prompt, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ImagesApi.create_image_edit ...'
  end
  # verify the required parameter 'image' is set
  if @api_client.config.client_side_validation && image.nil?
    fail ArgumentError, "Missing the required parameter 'image' when calling ImagesApi.create_image_edit"
  end
  # verify the required parameter 'prompt' is set
  if @api_client.config.client_side_validation && prompt.nil?
    fail ArgumentError, "Missing the required parameter 'prompt' when calling ImagesApi.create_image_edit"
  end
  if @api_client.config.client_side_validation && !opts[:'n'].nil? && opts[:'n'] > 10
    fail ArgumentError, 'invalid value for "opts[:"n"]" when calling ImagesApi.create_image_edit, must be smaller than or equal to 10.'
  end

  if @api_client.config.client_side_validation && !opts[:'n'].nil? && opts[:'n'] < 1
    fail ArgumentError, 'invalid value for "opts[:"n"]" when calling ImagesApi.create_image_edit, must be greater than or equal to 1.'
  end

  allowable_values = ["256x256", "512x512", "1024x1024"]
  if @api_client.config.client_side_validation && opts[:'size'] && !allowable_values.include?(opts[:'size'])
    fail ArgumentError, "invalid value for \"size\", must be one of #{allowable_values}"
  end
  allowable_values = ["url", "b64_json"]
  if @api_client.config.client_side_validation && opts[:'response_format'] && !allowable_values.include?(opts[:'response_format'])
    fail ArgumentError, "invalid value for \"response_format\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/images/edits'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['multipart/form-data'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}
  form_params['image'] = image
  form_params['prompt'] = prompt
  form_params['mask'] = opts[:'mask'] if !opts[:'mask'].nil?
  form_params['model'] = opts[:'model'] if !opts[:'model'].nil?
  form_params['n'] = opts[:'n'] if !opts[:'n'].nil?
  form_params['size'] = opts[:'size'] if !opts[:'size'].nil?
  form_params['response_format'] = opts[:'response_format'] if !opts[:'response_format'].nil?
  form_params['user'] = opts[:'user'] if !opts[:'user'].nil?

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'ImagesResponse'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"ImagesApi.create_image_edit",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ImagesApi#create_image_edit\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#create_image_variation(image, opts = {}) ⇒ ImagesResponse

Creates a variation of a given image.

Parameters:

  • image (File)

    The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.

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

    the optional parameters

Options Hash (opts):

  • :model (CreateImageEditRequestModel)
  • :n (Integer)

    The number of images to generate. Must be between 1 and 10. For &#x60;dall-e-3&#x60;, only &#x60;n&#x3D;1&#x60; is supported. (default to 1)

  • :response_format (String)

    The format in which the generated images are returned. Must be one of &#x60;url&#x60; or &#x60;b64_json&#x60;. URLs are only valid for 60 minutes after the image has been generated. (default to ‘url’)

  • :size (String)

    The size of the generated images. Must be one of &#x60;256x256&#x60;, &#x60;512x512&#x60;, or &#x60;1024x1024&#x60;. (default to ‘1024x1024’)

  • :user (String)

    A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).

Returns:



205
206
207
208
# File 'lib/openapi_openai/api/images_api.rb', line 205

def create_image_variation(image, opts = {})
  data, _status_code, _headers = create_image_variation_with_http_info(image, opts)
  data
end

#create_image_variation_with_http_info(image, opts = {}) ⇒ Array<(ImagesResponse, Integer, Hash)>

Creates a variation of a given image.

Parameters:

  • image (File)

    The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.

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

    the optional parameters

Options Hash (opts):

  • :model (CreateImageEditRequestModel)
  • :n (Integer)

    The number of images to generate. Must be between 1 and 10. For &#x60;dall-e-3&#x60;, only &#x60;n&#x3D;1&#x60; is supported. (default to 1)

  • :response_format (String)

    The format in which the generated images are returned. Must be one of &#x60;url&#x60; or &#x60;b64_json&#x60;. URLs are only valid for 60 minutes after the image has been generated. (default to ‘url’)

  • :size (String)

    The size of the generated images. Must be one of &#x60;256x256&#x60;, &#x60;512x512&#x60;, or &#x60;1024x1024&#x60;. (default to ‘1024x1024’)

  • :user (String)

    A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).

Returns:

  • (Array<(ImagesResponse, Integer, Hash)>)

    ImagesResponse data, response status code and response headers



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/openapi_openai/api/images_api.rb', line 219

def create_image_variation_with_http_info(image, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ImagesApi.create_image_variation ...'
  end
  # verify the required parameter 'image' is set
  if @api_client.config.client_side_validation && image.nil?
    fail ArgumentError, "Missing the required parameter 'image' when calling ImagesApi.create_image_variation"
  end
  if @api_client.config.client_side_validation && !opts[:'n'].nil? && opts[:'n'] > 10
    fail ArgumentError, 'invalid value for "opts[:"n"]" when calling ImagesApi.create_image_variation, must be smaller than or equal to 10.'
  end

  if @api_client.config.client_side_validation && !opts[:'n'].nil? && opts[:'n'] < 1
    fail ArgumentError, 'invalid value for "opts[:"n"]" when calling ImagesApi.create_image_variation, must be greater than or equal to 1.'
  end

  allowable_values = ["url", "b64_json"]
  if @api_client.config.client_side_validation && opts[:'response_format'] && !allowable_values.include?(opts[:'response_format'])
    fail ArgumentError, "invalid value for \"response_format\", must be one of #{allowable_values}"
  end
  allowable_values = ["256x256", "512x512", "1024x1024"]
  if @api_client.config.client_side_validation && opts[:'size'] && !allowable_values.include?(opts[:'size'])
    fail ArgumentError, "invalid value for \"size\", must be one of #{allowable_values}"
  end
  # resource path
  local_var_path = '/images/variations'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['multipart/form-data'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}
  form_params['image'] = image
  form_params['model'] = opts[:'model'] if !opts[:'model'].nil?
  form_params['n'] = opts[:'n'] if !opts[:'n'].nil?
  form_params['response_format'] = opts[:'response_format'] if !opts[:'response_format'].nil?
  form_params['size'] = opts[:'size'] if !opts[:'size'].nil?
  form_params['user'] = opts[:'user'] if !opts[:'user'].nil?

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'ImagesResponse'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"ImagesApi.create_image_variation",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ImagesApi#create_image_variation\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#create_image_with_http_info(create_image_request, opts = {}) ⇒ Array<(ImagesResponse, Integer, Hash)>

Creates an image given a prompt.

Parameters:

  • create_image_request (CreateImageRequest)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(ImagesResponse, Integer, Hash)>)

    ImagesResponse data, response status code and response headers



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/openapi_openai/api/images_api.rb', line 35

def create_image_with_http_info(create_image_request, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ImagesApi.create_image ...'
  end
  # verify the required parameter 'create_image_request' is set
  if @api_client.config.client_side_validation && create_image_request.nil?
    fail ArgumentError, "Missing the required parameter 'create_image_request' when calling ImagesApi.create_image"
  end
  # resource path
  local_var_path = '/images/generations'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(create_image_request)

  # return_type
  return_type = opts[:debug_return_type] || 'ImagesResponse'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"ImagesApi.create_image",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ImagesApi#create_image\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end