Class: OpenAI::Resources::Images
- Inherits:
-
Object
- Object
- OpenAI::Resources::Images
- Defined in:
- lib/openai/resources/images.rb
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 #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 #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 #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 #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.
292 293 294 |
# File 'lib/openai/resources/images.rb', line 292 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`.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/openai/resources/images.rb', line 31 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 #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`.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/openai/resources/images.rb', line 88 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 #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`.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/openai/resources/images.rb', line 149 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 #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](platform.openai.com/docs/guides/images).
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/openai/resources/images.rb', line 213 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 #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](platform.openai.com/docs/guides/images).
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/openai/resources/images.rb', line 270 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 |