Class: OpenAI::Resources::Images
- Inherits:
-
Object
- Object
- OpenAI::Resources::Images
- Defined in:
- lib/openai/resources/images.rb,
sig/openai/resources/images.rbs
Overview
Given a prompt and/or an input image, the model will generate a new image.
Instance Method Summary collapse
-
#create_variation(image:, model: nil, n: nil, response_format: nil, size: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse
Some parameter documentations has been truncated, see Models::ImageCreateVariationParams for more details.
-
#edit(image:, prompt:, background: nil, input_fidelity: nil, mask: nil, model: nil, n: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, response_format: nil, size: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse
See OpenAI::Resources::Images#edit_stream_raw for streaming counterpart.
-
#edit_stream_raw(image:, prompt:, background: nil, input_fidelity: nil, mask: nil, model: nil, n: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, response_format: nil, size: nil, user: nil, request_options: {}) ⇒ OpenAI::Internal::Stream<OpenAI::Models::ImageEditPartialImageEvent, OpenAI::Models::ImageEditCompletedEvent>
See OpenAI::Resources::Images#edit for non-streaming counterpart.
-
#generate(prompt:, background: nil, model: nil, moderation: nil, n: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, response_format: nil, size: nil, style: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse
See OpenAI::Resources::Images#generate_stream_raw for streaming counterpart.
-
#generate_stream_raw(prompt:, background: nil, model: nil, moderation: nil, n: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, response_format: nil, size: nil, style: nil, user: nil, request_options: {}) ⇒ OpenAI::Internal::Stream<OpenAI::Models::ImageGenPartialImageEvent, OpenAI::Models::ImageGenCompletedEvent>
See OpenAI::Resources::Images#generate for non-streaming counterpart.
-
#initialize(client:) ⇒ Images
constructor
private
A new instance of Images.
Constructor Details
#initialize(client:) ⇒ Images
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Images.
304 305 306 |
# File 'lib/openai/resources/images.rb', line 304 def initialize(client:) @client = client end |
Instance Method Details
#create_variation(image:, model: nil, n: nil, response_format: nil, size: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse
Some parameter documentations has been truncated, see Models::ImageCreateVariationParams for more details.
Creates a variation of a given image. This endpoint only supports dall-e-2.
String, StringIO, and pathless IO inputs are sent with generic upload
metadata. Use OpenAI::FilePart when you need to override the filename or
content type.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/openai/resources/images.rb', line 35 def create_variation(params) parsed, = OpenAI::ImageCreateVariationParams.dump_request(params) @client.request( method: :post, path: "images/variations", headers: {"content-type" => "multipart/form-data"}, body: parsed, model: OpenAI::ImagesResponse, security: {bearer_auth: true}, options: ) end |
#edit(image:, prompt:, background: nil, input_fidelity: nil, mask: nil, model: nil, n: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, response_format: nil, size: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse
See OpenAI::Resources::Images#edit_stream_raw for streaming counterpart.
Some parameter documentations has been truncated, see Models::ImageEditParams for more details.
Creates an edited or extended image given one or more source images and a
prompt. This endpoint supports GPT Image models (gpt-image-1.5, gpt-image-1,
gpt-image-1-mini, and chatgpt-image-latest) and dall-e-2.
String, StringIO, and pathless IO inputs are sent with generic upload
metadata. Use OpenAI::FilePart when you need to override the filename or
content type.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/openai/resources/images.rb', line 96 def edit(params) parsed, = OpenAI::ImageEditParams.dump_request(params) if parsed[:stream] = "Please use `#edit_stream_raw` for the streaming use case." raise ArgumentError.new() end @client.request( method: :post, path: "images/edits", headers: {"content-type" => "multipart/form-data"}, body: parsed, model: OpenAI::ImagesResponse, security: {bearer_auth: true}, options: ) end |
#edit_stream_raw(image:, prompt:, background: nil, input_fidelity: nil, mask: nil, model: nil, n: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, response_format: nil, size: nil, user: nil, request_options: {}) ⇒ OpenAI::Internal::Stream<OpenAI::Models::ImageEditPartialImageEvent, OpenAI::Models::ImageEditCompletedEvent>
See OpenAI::Resources::Images#edit for non-streaming counterpart.
Some parameter documentations has been truncated, see Models::ImageEditParams for more details.
Creates an edited or extended image given one or more source images and a
prompt. This endpoint supports GPT Image models (gpt-image-1.5, gpt-image-1,
gpt-image-1-mini, and chatgpt-image-latest) and dall-e-2.
String, StringIO, and pathless IO inputs are sent with generic upload
metadata. Use OpenAI::FilePart when you need to override the filename or
content type.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/openai/resources/images.rb', line 161 def edit_stream_raw(params) parsed, = OpenAI::ImageEditParams.dump_request(params) unless parsed.fetch(:stream, true) = "Please use `#edit` for the non-streaming use case." raise ArgumentError.new() end parsed.store(:stream, true) @client.request( method: :post, path: "images/edits", headers: { "content-type" => "multipart/form-data", "accept" => "text/event-stream", "accept-encoding" => "identity" }, body: parsed, stream: OpenAI::Internal::Stream, model: OpenAI::ImageEditStreamEvent, security: {bearer_auth: true}, options: ) end |
#generate(prompt:, background: nil, model: nil, moderation: nil, n: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, response_format: nil, size: nil, style: nil, user: nil, request_options: {}) ⇒ OpenAI::Models::ImagesResponse
See OpenAI::Resources::Images#generate_stream_raw for streaming counterpart.
Some parameter documentations has been truncated, see Models::ImageGenerateParams for more details.
Creates an image given a prompt. Learn more.
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/openai/resources/images.rb', line 225 def generate(params) parsed, = OpenAI::ImageGenerateParams.dump_request(params) if parsed[:stream] = "Please use `#generate_stream_raw` for the streaming use case." raise ArgumentError.new() end @client.request( method: :post, path: "images/generations", body: parsed, model: OpenAI::ImagesResponse, security: {bearer_auth: true}, options: ) end |
#generate_stream_raw(prompt:, background: nil, model: nil, moderation: nil, n: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, response_format: nil, size: nil, style: nil, user: nil, request_options: {}) ⇒ OpenAI::Internal::Stream<OpenAI::Models::ImageGenPartialImageEvent, OpenAI::Models::ImageGenCompletedEvent>
See OpenAI::Resources::Images#generate for non-streaming counterpart.
Some parameter documentations has been truncated, see Models::ImageGenerateParams for more details.
Creates an image given a prompt. Learn more.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/openai/resources/images.rb', line 282 def generate_stream_raw(params) parsed, = OpenAI::ImageGenerateParams.dump_request(params) unless parsed.fetch(:stream, true) = "Please use `#generate` for the non-streaming use case." raise ArgumentError.new() end parsed.store(:stream, true) @client.request( method: :post, path: "images/generations", headers: {"accept" => "text/event-stream", "accept-encoding" => "identity"}, body: parsed, stream: OpenAI::Internal::Stream, model: OpenAI::ImageGenStreamEvent, security: {bearer_auth: true}, options: ) end |