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
Creates a variation of a given image.
-
#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.
598 599 600 |
# File 'lib/openai/resources/images.rb', line 598 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
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.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/openai/resources/images.rb', line 49 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.
Creates an edited or extended image given one or more source images and a
prompt. This endpoint supports GPT Image models 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.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/openai/resources/images.rb', line 185 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.
Creates an edited or extended image given one or more source images and a
prompt. This endpoint supports GPT Image models 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.
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/openai/resources/images.rb', line 326 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.
Creates an image given a prompt. Learn more.
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/openai/resources/images.rb', line 454 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.
Creates an image given a prompt. Learn more.
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/openai/resources/images.rb', line 575 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 |