openai 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +1 -1
- data/lib/openai/models/image_edit_completed_event.rb +198 -0
- data/lib/openai/models/image_edit_params.rb +36 -1
- data/lib/openai/models/image_edit_partial_image_event.rb +135 -0
- data/lib/openai/models/image_edit_stream_event.rb +21 -0
- data/lib/openai/models/image_gen_completed_event.rb +198 -0
- data/lib/openai/models/image_gen_partial_image_event.rb +135 -0
- data/lib/openai/models/image_gen_stream_event.rb +21 -0
- data/lib/openai/models/image_generate_params.rb +13 -1
- data/lib/openai/models/images_response.rb +3 -0
- data/lib/openai/models/responses/response_output_refusal.rb +2 -2
- data/lib/openai/models/responses/tool.rb +30 -1
- data/lib/openai/models.rb +12 -0
- data/lib/openai/resources/images.rb +140 -2
- data/lib/openai/version.rb +1 -1
- data/lib/openai.rb +6 -0
- data/rbi/openai/models/image_edit_completed_event.rbi +346 -0
- data/rbi/openai/models/image_edit_params.rbi +51 -0
- data/rbi/openai/models/image_edit_partial_image_event.rbi +249 -0
- data/rbi/openai/models/image_edit_stream_event.rbi +22 -0
- data/rbi/openai/models/image_gen_completed_event.rbi +339 -0
- data/rbi/openai/models/image_gen_partial_image_event.rbi +243 -0
- data/rbi/openai/models/image_gen_stream_event.rbi +22 -0
- data/rbi/openai/models/image_generate_params.rbi +12 -0
- data/rbi/openai/models/responses/response_output_refusal.rbi +2 -2
- data/rbi/openai/models/responses/tool.rbi +61 -0
- data/rbi/openai/models.rbi +12 -0
- data/rbi/openai/resources/images.rbi +225 -0
- data/sig/openai/models/image_edit_completed_event.rbs +150 -0
- data/sig/openai/models/image_edit_params.rbs +21 -0
- data/sig/openai/models/image_edit_partial_image_event.rbs +105 -0
- data/sig/openai/models/image_edit_stream_event.rbs +12 -0
- data/sig/openai/models/image_gen_completed_event.rbs +150 -0
- data/sig/openai/models/image_gen_partial_image_event.rbs +105 -0
- data/sig/openai/models/image_gen_stream_event.rbs +12 -0
- data/sig/openai/models/image_generate_params.rbs +5 -0
- data/sig/openai/models/responses/tool.rbs +16 -0
- data/sig/openai/models.rbs +12 -0
- data/sig/openai/resources/images.rbs +38 -0
- metadata +20 -2
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenAI
|
4
|
+
module Models
|
5
|
+
class ImageGenPartialImageEvent < OpenAI::Internal::Type::BaseModel
|
6
|
+
# @!attribute b64_json
|
7
|
+
# Base64-encoded partial image data, suitable for rendering as an image.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
required :b64_json, String
|
11
|
+
|
12
|
+
# @!attribute background
|
13
|
+
# The background setting for the requested image.
|
14
|
+
#
|
15
|
+
# @return [Symbol, OpenAI::Models::ImageGenPartialImageEvent::Background]
|
16
|
+
required :background, enum: -> { OpenAI::ImageGenPartialImageEvent::Background }
|
17
|
+
|
18
|
+
# @!attribute created_at
|
19
|
+
# The Unix timestamp when the event was created.
|
20
|
+
#
|
21
|
+
# @return [Integer]
|
22
|
+
required :created_at, Integer
|
23
|
+
|
24
|
+
# @!attribute output_format
|
25
|
+
# The output format for the requested image.
|
26
|
+
#
|
27
|
+
# @return [Symbol, OpenAI::Models::ImageGenPartialImageEvent::OutputFormat]
|
28
|
+
required :output_format, enum: -> { OpenAI::ImageGenPartialImageEvent::OutputFormat }
|
29
|
+
|
30
|
+
# @!attribute partial_image_index
|
31
|
+
# 0-based index for the partial image (streaming).
|
32
|
+
#
|
33
|
+
# @return [Integer]
|
34
|
+
required :partial_image_index, Integer
|
35
|
+
|
36
|
+
# @!attribute quality
|
37
|
+
# The quality setting for the requested image.
|
38
|
+
#
|
39
|
+
# @return [Symbol, OpenAI::Models::ImageGenPartialImageEvent::Quality]
|
40
|
+
required :quality, enum: -> { OpenAI::ImageGenPartialImageEvent::Quality }
|
41
|
+
|
42
|
+
# @!attribute size
|
43
|
+
# The size of the requested image.
|
44
|
+
#
|
45
|
+
# @return [Symbol, OpenAI::Models::ImageGenPartialImageEvent::Size]
|
46
|
+
required :size, enum: -> { OpenAI::ImageGenPartialImageEvent::Size }
|
47
|
+
|
48
|
+
# @!attribute type
|
49
|
+
# The type of the event. Always `image_generation.partial_image`.
|
50
|
+
#
|
51
|
+
# @return [Symbol, :"image_generation.partial_image"]
|
52
|
+
required :type, const: :"image_generation.partial_image"
|
53
|
+
|
54
|
+
# @!method initialize(b64_json:, background:, created_at:, output_format:, partial_image_index:, quality:, size:, type: :"image_generation.partial_image")
|
55
|
+
# Some parameter documentations has been truncated, see
|
56
|
+
# {OpenAI::Models::ImageGenPartialImageEvent} for more details.
|
57
|
+
#
|
58
|
+
# Emitted when a partial image is available during image generation streaming.
|
59
|
+
#
|
60
|
+
# @param b64_json [String] Base64-encoded partial image data, suitable for rendering as an image.
|
61
|
+
#
|
62
|
+
# @param background [Symbol, OpenAI::Models::ImageGenPartialImageEvent::Background] The background setting for the requested image.
|
63
|
+
#
|
64
|
+
# @param created_at [Integer] The Unix timestamp when the event was created.
|
65
|
+
#
|
66
|
+
# @param output_format [Symbol, OpenAI::Models::ImageGenPartialImageEvent::OutputFormat] The output format for the requested image.
|
67
|
+
#
|
68
|
+
# @param partial_image_index [Integer] 0-based index for the partial image (streaming).
|
69
|
+
#
|
70
|
+
# @param quality [Symbol, OpenAI::Models::ImageGenPartialImageEvent::Quality] The quality setting for the requested image.
|
71
|
+
#
|
72
|
+
# @param size [Symbol, OpenAI::Models::ImageGenPartialImageEvent::Size] The size of the requested image.
|
73
|
+
#
|
74
|
+
# @param type [Symbol, :"image_generation.partial_image"] The type of the event. Always `image_generation.partial_image`.
|
75
|
+
|
76
|
+
# The background setting for the requested image.
|
77
|
+
#
|
78
|
+
# @see OpenAI::Models::ImageGenPartialImageEvent#background
|
79
|
+
module Background
|
80
|
+
extend OpenAI::Internal::Type::Enum
|
81
|
+
|
82
|
+
TRANSPARENT = :transparent
|
83
|
+
OPAQUE = :opaque
|
84
|
+
AUTO = :auto
|
85
|
+
|
86
|
+
# @!method self.values
|
87
|
+
# @return [Array<Symbol>]
|
88
|
+
end
|
89
|
+
|
90
|
+
# The output format for the requested image.
|
91
|
+
#
|
92
|
+
# @see OpenAI::Models::ImageGenPartialImageEvent#output_format
|
93
|
+
module OutputFormat
|
94
|
+
extend OpenAI::Internal::Type::Enum
|
95
|
+
|
96
|
+
PNG = :png
|
97
|
+
WEBP = :webp
|
98
|
+
JPEG = :jpeg
|
99
|
+
|
100
|
+
# @!method self.values
|
101
|
+
# @return [Array<Symbol>]
|
102
|
+
end
|
103
|
+
|
104
|
+
# The quality setting for the requested image.
|
105
|
+
#
|
106
|
+
# @see OpenAI::Models::ImageGenPartialImageEvent#quality
|
107
|
+
module Quality
|
108
|
+
extend OpenAI::Internal::Type::Enum
|
109
|
+
|
110
|
+
LOW = :low
|
111
|
+
MEDIUM = :medium
|
112
|
+
HIGH = :high
|
113
|
+
AUTO = :auto
|
114
|
+
|
115
|
+
# @!method self.values
|
116
|
+
# @return [Array<Symbol>]
|
117
|
+
end
|
118
|
+
|
119
|
+
# The size of the requested image.
|
120
|
+
#
|
121
|
+
# @see OpenAI::Models::ImageGenPartialImageEvent#size
|
122
|
+
module Size
|
123
|
+
extend OpenAI::Internal::Type::Enum
|
124
|
+
|
125
|
+
SIZE_1024X1024 = :"1024x1024"
|
126
|
+
SIZE_1024X1536 = :"1024x1536"
|
127
|
+
SIZE_1536X1024 = :"1536x1024"
|
128
|
+
AUTO = :auto
|
129
|
+
|
130
|
+
# @!method self.values
|
131
|
+
# @return [Array<Symbol>]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenAI
|
4
|
+
module Models
|
5
|
+
# Emitted when a partial image is available during image generation streaming.
|
6
|
+
module ImageGenStreamEvent
|
7
|
+
extend OpenAI::Internal::Type::Union
|
8
|
+
|
9
|
+
discriminator :type
|
10
|
+
|
11
|
+
# Emitted when a partial image is available during image generation streaming.
|
12
|
+
variant :"image_generation.partial_image", -> { OpenAI::ImageGenPartialImageEvent }
|
13
|
+
|
14
|
+
# Emitted when image generation has completed and the final image is available.
|
15
|
+
variant :"image_generation.completed", -> { OpenAI::ImageGenCompletedEvent }
|
16
|
+
|
17
|
+
# @!method self.variants
|
18
|
+
# @return [Array(OpenAI::Models::ImageGenPartialImageEvent, OpenAI::Models::ImageGenCompletedEvent)]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module OpenAI
|
4
4
|
module Models
|
5
5
|
# @see OpenAI::Resources::Images#generate
|
6
|
+
#
|
7
|
+
# @see OpenAI::Resources::Images#stream_raw
|
6
8
|
class ImageGenerateParams < OpenAI::Internal::Type::BaseModel
|
7
9
|
extend OpenAI::Internal::Type::RequestParameters::Converter
|
8
10
|
include OpenAI::Internal::Type::RequestParameters
|
@@ -64,6 +66,14 @@ module OpenAI
|
|
64
66
|
# @return [Symbol, OpenAI::Models::ImageGenerateParams::OutputFormat, nil]
|
65
67
|
optional :output_format, enum: -> { OpenAI::ImageGenerateParams::OutputFormat }, nil?: true
|
66
68
|
|
69
|
+
# @!attribute partial_images
|
70
|
+
# The number of partial images to generate. This parameter is used for streaming
|
71
|
+
# responses that return partial images. Value must be between 0 and 3. When set to
|
72
|
+
# 0, the response will be a single image sent in one streaming event.
|
73
|
+
#
|
74
|
+
# @return [Integer, nil]
|
75
|
+
optional :partial_images, Integer, nil?: true
|
76
|
+
|
67
77
|
# @!attribute quality
|
68
78
|
# The quality of the image that will be generated.
|
69
79
|
#
|
@@ -111,7 +121,7 @@ module OpenAI
|
|
111
121
|
# @return [String, nil]
|
112
122
|
optional :user, String
|
113
123
|
|
114
|
-
# @!method initialize(prompt:, background: nil, model: nil, moderation: nil, n: nil, output_compression: nil, output_format: nil, quality: nil, response_format: nil, size: nil, style: nil, user: nil, request_options: {})
|
124
|
+
# @!method initialize(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: {})
|
115
125
|
# Some parameter documentations has been truncated, see
|
116
126
|
# {OpenAI::Models::ImageGenerateParams} for more details.
|
117
127
|
#
|
@@ -129,6 +139,8 @@ module OpenAI
|
|
129
139
|
#
|
130
140
|
# @param output_format [Symbol, OpenAI::Models::ImageGenerateParams::OutputFormat, nil] The format in which the generated images are returned. This parameter is only su
|
131
141
|
#
|
142
|
+
# @param partial_images [Integer, nil] The number of partial images to generate. This parameter is used for
|
143
|
+
#
|
132
144
|
# @param quality [Symbol, OpenAI::Models::ImageGenerateParams::Quality, nil] The quality of the image that will be generated.
|
133
145
|
#
|
134
146
|
# @param response_format [Symbol, OpenAI::Models::ImageGenerateParams::ResponseFormat, nil] The format in which generated images with `dall-e-2` and `dall-e-3` are returned
|
@@ -152,6 +152,9 @@ module OpenAI
|
|
152
152
|
required :total_tokens, Integer
|
153
153
|
|
154
154
|
# @!method initialize(input_tokens:, input_tokens_details:, output_tokens:, total_tokens:)
|
155
|
+
# Some parameter documentations has been truncated, see
|
156
|
+
# {OpenAI::Models::ImagesResponse::Usage} for more details.
|
157
|
+
#
|
155
158
|
# For `gpt-image-1` only, the token usage information for the image generation.
|
156
159
|
#
|
157
160
|
# @param input_tokens [Integer] The number of tokens (images and text) in the input prompt.
|
@@ -5,7 +5,7 @@ module OpenAI
|
|
5
5
|
module Responses
|
6
6
|
class ResponseOutputRefusal < OpenAI::Internal::Type::BaseModel
|
7
7
|
# @!attribute refusal
|
8
|
-
# The refusal
|
8
|
+
# The refusal explanation from the model.
|
9
9
|
#
|
10
10
|
# @return [String]
|
11
11
|
required :refusal, String
|
@@ -19,7 +19,7 @@ module OpenAI
|
|
19
19
|
# @!method initialize(refusal:, type: :refusal)
|
20
20
|
# A refusal from the model.
|
21
21
|
#
|
22
|
-
# @param refusal [String] The refusal
|
22
|
+
# @param refusal [String] The refusal explanation from the model.
|
23
23
|
#
|
24
24
|
# @param type [Symbol, :refusal] The type of the refusal. Always `refusal`.
|
25
25
|
end
|
@@ -305,6 +305,18 @@ module OpenAI
|
|
305
305
|
# @return [Symbol, OpenAI::Models::Responses::Tool::ImageGeneration::Background, nil]
|
306
306
|
optional :background, enum: -> { OpenAI::Responses::Tool::ImageGeneration::Background }
|
307
307
|
|
308
|
+
# @!attribute input_fidelity
|
309
|
+
# Control how much effort the model will exert to match the style and features,
|
310
|
+
# especially facial features, of input images. This parameter is only supported
|
311
|
+
# for `gpt-image-1`. Supports `high` and `low`. Defaults to `low`.
|
312
|
+
#
|
313
|
+
# @return [Symbol, OpenAI::Models::Responses::Tool::ImageGeneration::InputFidelity, nil]
|
314
|
+
optional :input_fidelity,
|
315
|
+
enum: -> {
|
316
|
+
OpenAI::Responses::Tool::ImageGeneration::InputFidelity
|
317
|
+
},
|
318
|
+
nil?: true
|
319
|
+
|
308
320
|
# @!attribute input_image_mask
|
309
321
|
# Optional mask for inpainting. Contains `image_url` (string, optional) and
|
310
322
|
# `file_id` (string, optional).
|
@@ -358,7 +370,7 @@ module OpenAI
|
|
358
370
|
# @return [Symbol, OpenAI::Models::Responses::Tool::ImageGeneration::Size, nil]
|
359
371
|
optional :size, enum: -> { OpenAI::Responses::Tool::ImageGeneration::Size }
|
360
372
|
|
361
|
-
# @!method initialize(background: nil, input_image_mask: nil, model: nil, moderation: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, size: nil, type: :image_generation)
|
373
|
+
# @!method initialize(background: nil, input_fidelity: nil, input_image_mask: nil, model: nil, moderation: nil, output_compression: nil, output_format: nil, partial_images: nil, quality: nil, size: nil, type: :image_generation)
|
362
374
|
# Some parameter documentations has been truncated, see
|
363
375
|
# {OpenAI::Models::Responses::Tool::ImageGeneration} for more details.
|
364
376
|
#
|
@@ -366,6 +378,8 @@ module OpenAI
|
|
366
378
|
#
|
367
379
|
# @param background [Symbol, OpenAI::Models::Responses::Tool::ImageGeneration::Background] Background type for the generated image. One of `transparent`,
|
368
380
|
#
|
381
|
+
# @param input_fidelity [Symbol, OpenAI::Models::Responses::Tool::ImageGeneration::InputFidelity, nil] Control how much effort the model will exert to match the style and features,
|
382
|
+
#
|
369
383
|
# @param input_image_mask [OpenAI::Models::Responses::Tool::ImageGeneration::InputImageMask] Optional mask for inpainting. Contains `image_url`
|
370
384
|
#
|
371
385
|
# @param model [Symbol, OpenAI::Models::Responses::Tool::ImageGeneration::Model] The image generation model to use. Default: `gpt-image-1`.
|
@@ -399,6 +413,21 @@ module OpenAI
|
|
399
413
|
# @return [Array<Symbol>]
|
400
414
|
end
|
401
415
|
|
416
|
+
# Control how much effort the model will exert to match the style and features,
|
417
|
+
# especially facial features, of input images. This parameter is only supported
|
418
|
+
# for `gpt-image-1`. Supports `high` and `low`. Defaults to `low`.
|
419
|
+
#
|
420
|
+
# @see OpenAI::Models::Responses::Tool::ImageGeneration#input_fidelity
|
421
|
+
module InputFidelity
|
422
|
+
extend OpenAI::Internal::Type::Enum
|
423
|
+
|
424
|
+
HIGH = :high
|
425
|
+
LOW = :low
|
426
|
+
|
427
|
+
# @!method self.values
|
428
|
+
# @return [Array<Symbol>]
|
429
|
+
end
|
430
|
+
|
402
431
|
# @see OpenAI::Models::Responses::Tool::ImageGeneration#input_image_mask
|
403
432
|
class InputImageMask < OpenAI::Internal::Type::BaseModel
|
404
433
|
# @!attribute file_id
|
data/lib/openai/models.rb
CHANGED
@@ -152,10 +152,22 @@ module OpenAI
|
|
152
152
|
|
153
153
|
ImageCreateVariationParams = OpenAI::Models::ImageCreateVariationParams
|
154
154
|
|
155
|
+
ImageEditCompletedEvent = OpenAI::Models::ImageEditCompletedEvent
|
156
|
+
|
155
157
|
ImageEditParams = OpenAI::Models::ImageEditParams
|
156
158
|
|
159
|
+
ImageEditPartialImageEvent = OpenAI::Models::ImageEditPartialImageEvent
|
160
|
+
|
161
|
+
ImageEditStreamEvent = OpenAI::Models::ImageEditStreamEvent
|
162
|
+
|
163
|
+
ImageGenCompletedEvent = OpenAI::Models::ImageGenCompletedEvent
|
164
|
+
|
157
165
|
ImageGenerateParams = OpenAI::Models::ImageGenerateParams
|
158
166
|
|
167
|
+
ImageGenPartialImageEvent = OpenAI::Models::ImageGenPartialImageEvent
|
168
|
+
|
169
|
+
ImageGenStreamEvent = OpenAI::Models::ImageGenStreamEvent
|
170
|
+
|
159
171
|
ImageModel = OpenAI::Models::ImageModel
|
160
172
|
|
161
173
|
ImagesResponse = OpenAI::Models::ImagesResponse
|
@@ -39,13 +39,15 @@ module OpenAI
|
|
39
39
|
)
|
40
40
|
end
|
41
41
|
|
42
|
+
# See {OpenAI::Resources::Images#stream_raw} for streaming counterpart.
|
43
|
+
#
|
42
44
|
# Some parameter documentations has been truncated, see
|
43
45
|
# {OpenAI::Models::ImageEditParams} for more details.
|
44
46
|
#
|
45
47
|
# Creates an edited or extended image given one or more source images and a
|
46
48
|
# prompt. This endpoint only supports `gpt-image-1` and `dall-e-2`.
|
47
49
|
#
|
48
|
-
# @overload edit(image:, prompt:, background: nil, mask: nil, model: nil, n: nil, output_compression: nil, output_format: nil, quality: nil, response_format: nil, size: nil, user: nil, request_options: {})
|
50
|
+
# @overload 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: {})
|
49
51
|
#
|
50
52
|
# @param image [Pathname, StringIO, IO, String, OpenAI::FilePart, Array<Pathname, StringIO, IO, String, OpenAI::FilePart>] The image(s) to edit. Must be a supported image file or an array of images.
|
51
53
|
#
|
@@ -53,6 +55,8 @@ module OpenAI
|
|
53
55
|
#
|
54
56
|
# @param background [Symbol, OpenAI::Models::ImageEditParams::Background, nil] Allows to set transparency for the background of the generated image(s).
|
55
57
|
#
|
58
|
+
# @param input_fidelity [Symbol, OpenAI::Models::ImageEditParams::InputFidelity, nil] Control how much effort the model will exert to match the style and features,
|
59
|
+
#
|
56
60
|
# @param mask [Pathname, StringIO, IO, String, OpenAI::FilePart] An additional image whose fully transparent areas (e.g. where alpha is zero) ind
|
57
61
|
#
|
58
62
|
# @param model [String, Symbol, OpenAI::Models::ImageModel, nil] The model to use for image generation. Only `dall-e-2` and `gpt-image-1` are sup
|
@@ -63,6 +67,8 @@ module OpenAI
|
|
63
67
|
#
|
64
68
|
# @param output_format [Symbol, OpenAI::Models::ImageEditParams::OutputFormat, nil] The format in which the generated images are returned. This parameter is
|
65
69
|
#
|
70
|
+
# @param partial_images [Integer, nil] The number of partial images to generate. This parameter is used for
|
71
|
+
#
|
66
72
|
# @param quality [Symbol, OpenAI::Models::ImageEditParams::Quality, nil] The quality of the image that will be generated. `high`, `medium` and `low` are
|
67
73
|
#
|
68
74
|
# @param response_format [Symbol, OpenAI::Models::ImageEditParams::ResponseFormat, nil] The format in which the generated images are returned. Must be one of `url` or `
|
@@ -78,6 +84,10 @@ module OpenAI
|
|
78
84
|
# @see OpenAI::Models::ImageEditParams
|
79
85
|
def edit(params)
|
80
86
|
parsed, options = OpenAI::ImageEditParams.dump_request(params)
|
87
|
+
if parsed[:stream]
|
88
|
+
message = "Please use `#stream_raw` for the streaming use case."
|
89
|
+
raise ArgumentError.new(message)
|
90
|
+
end
|
81
91
|
@client.request(
|
82
92
|
method: :post,
|
83
93
|
path: "images/edits",
|
@@ -88,13 +98,76 @@ module OpenAI
|
|
88
98
|
)
|
89
99
|
end
|
90
100
|
|
101
|
+
# See {OpenAI::Resources::Images#edit} for non-streaming counterpart.
|
102
|
+
#
|
103
|
+
# Some parameter documentations has been truncated, see
|
104
|
+
# {OpenAI::Models::ImageEditParams} for more details.
|
105
|
+
#
|
106
|
+
# Creates an edited or extended image given one or more source images and a
|
107
|
+
# prompt. This endpoint only supports `gpt-image-1` and `dall-e-2`.
|
108
|
+
#
|
109
|
+
# @overload 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: {})
|
110
|
+
#
|
111
|
+
# @param image [Pathname, StringIO, IO, String, OpenAI::FilePart, Array<Pathname, StringIO, IO, String, OpenAI::FilePart>] The image(s) to edit. Must be a supported image file or an array of images.
|
112
|
+
#
|
113
|
+
# @param prompt [String] A text description of the desired image(s). The maximum length is 1000 character
|
114
|
+
#
|
115
|
+
# @param background [Symbol, OpenAI::Models::ImageEditParams::Background, nil] Allows to set transparency for the background of the generated image(s).
|
116
|
+
#
|
117
|
+
# @param input_fidelity [Symbol, OpenAI::Models::ImageEditParams::InputFidelity, nil] Control how much effort the model will exert to match the style and features,
|
118
|
+
#
|
119
|
+
# @param mask [Pathname, StringIO, IO, String, OpenAI::FilePart] An additional image whose fully transparent areas (e.g. where alpha is zero) ind
|
120
|
+
#
|
121
|
+
# @param model [String, Symbol, OpenAI::Models::ImageModel, nil] The model to use for image generation. Only `dall-e-2` and `gpt-image-1` are sup
|
122
|
+
#
|
123
|
+
# @param n [Integer, nil] The number of images to generate. Must be between 1 and 10.
|
124
|
+
#
|
125
|
+
# @param output_compression [Integer, nil] The compression level (0-100%) for the generated images. This parameter
|
126
|
+
#
|
127
|
+
# @param output_format [Symbol, OpenAI::Models::ImageEditParams::OutputFormat, nil] The format in which the generated images are returned. This parameter is
|
128
|
+
#
|
129
|
+
# @param partial_images [Integer, nil] The number of partial images to generate. This parameter is used for
|
130
|
+
#
|
131
|
+
# @param quality [Symbol, OpenAI::Models::ImageEditParams::Quality, nil] The quality of the image that will be generated. `high`, `medium` and `low` are
|
132
|
+
#
|
133
|
+
# @param response_format [Symbol, OpenAI::Models::ImageEditParams::ResponseFormat, nil] The format in which the generated images are returned. Must be one of `url` or `
|
134
|
+
#
|
135
|
+
# @param size [Symbol, OpenAI::Models::ImageEditParams::Size, nil] The size of the generated images. Must be one of `1024x1024`, `1536x1024` (lands
|
136
|
+
#
|
137
|
+
# @param user [String] A unique identifier representing your end-user, which can help OpenAI to monitor
|
138
|
+
#
|
139
|
+
# @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil]
|
140
|
+
#
|
141
|
+
# @return [OpenAI::Internal::Stream<OpenAI::Models::ImageEditPartialImageEvent, OpenAI::Models::ImageEditCompletedEvent>]
|
142
|
+
#
|
143
|
+
# @see OpenAI::Models::ImageEditParams
|
144
|
+
def edit_stream_raw(params)
|
145
|
+
parsed, options = OpenAI::ImageEditParams.dump_request(params)
|
146
|
+
unless parsed.fetch(:stream, true)
|
147
|
+
message = "Please use `#edit` for the non-streaming use case."
|
148
|
+
raise ArgumentError.new(message)
|
149
|
+
end
|
150
|
+
parsed.store(:stream, true)
|
151
|
+
@client.request(
|
152
|
+
method: :post,
|
153
|
+
path: "images/edits",
|
154
|
+
headers: {"content-type" => "multipart/form-data", "accept" => "text/event-stream"},
|
155
|
+
body: parsed,
|
156
|
+
stream: OpenAI::Internal::Stream,
|
157
|
+
model: OpenAI::ImageEditStreamEvent,
|
158
|
+
options: options
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
# See {OpenAI::Resources::Images#stream_raw} for streaming counterpart.
|
163
|
+
#
|
91
164
|
# Some parameter documentations has been truncated, see
|
92
165
|
# {OpenAI::Models::ImageGenerateParams} for more details.
|
93
166
|
#
|
94
167
|
# Creates an image given a prompt.
|
95
168
|
# [Learn more](https://platform.openai.com/docs/guides/images).
|
96
169
|
#
|
97
|
-
# @overload generate(prompt:, background: nil, model: nil, moderation: nil, n: nil, output_compression: nil, output_format: nil, quality: nil, response_format: nil, size: nil, style: nil, user: nil, request_options: {})
|
170
|
+
# @overload 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: {})
|
98
171
|
#
|
99
172
|
# @param prompt [String] A text description of the desired image(s). The maximum length is 32000 characte
|
100
173
|
#
|
@@ -110,6 +183,8 @@ module OpenAI
|
|
110
183
|
#
|
111
184
|
# @param output_format [Symbol, OpenAI::Models::ImageGenerateParams::OutputFormat, nil] The format in which the generated images are returned. This parameter is only su
|
112
185
|
#
|
186
|
+
# @param partial_images [Integer, nil] The number of partial images to generate. This parameter is used for
|
187
|
+
#
|
113
188
|
# @param quality [Symbol, OpenAI::Models::ImageGenerateParams::Quality, nil] The quality of the image that will be generated.
|
114
189
|
#
|
115
190
|
# @param response_format [Symbol, OpenAI::Models::ImageGenerateParams::ResponseFormat, nil] The format in which generated images with `dall-e-2` and `dall-e-3` are returned
|
@@ -127,6 +202,10 @@ module OpenAI
|
|
127
202
|
# @see OpenAI::Models::ImageGenerateParams
|
128
203
|
def generate(params)
|
129
204
|
parsed, options = OpenAI::ImageGenerateParams.dump_request(params)
|
205
|
+
if parsed[:stream]
|
206
|
+
message = "Please use `#stream_raw` for the streaming use case."
|
207
|
+
raise ArgumentError.new(message)
|
208
|
+
end
|
130
209
|
@client.request(
|
131
210
|
method: :post,
|
132
211
|
path: "images/generations",
|
@@ -136,6 +215,65 @@ module OpenAI
|
|
136
215
|
)
|
137
216
|
end
|
138
217
|
|
218
|
+
# See {OpenAI::Resources::Images#generate} for non-streaming counterpart.
|
219
|
+
#
|
220
|
+
# Some parameter documentations has been truncated, see
|
221
|
+
# {OpenAI::Models::ImageGenerateParams} for more details.
|
222
|
+
#
|
223
|
+
# Creates an image given a prompt.
|
224
|
+
# [Learn more](https://platform.openai.com/docs/guides/images).
|
225
|
+
#
|
226
|
+
# @overload 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: {})
|
227
|
+
#
|
228
|
+
# @param prompt [String] A text description of the desired image(s). The maximum length is 32000 characte
|
229
|
+
#
|
230
|
+
# @param background [Symbol, OpenAI::Models::ImageGenerateParams::Background, nil] Allows to set transparency for the background of the generated image(s).
|
231
|
+
#
|
232
|
+
# @param model [String, Symbol, OpenAI::Models::ImageModel, nil] The model to use for image generation. One of `dall-e-2`, `dall-e-3`, or `gpt-im
|
233
|
+
#
|
234
|
+
# @param moderation [Symbol, OpenAI::Models::ImageGenerateParams::Moderation, nil] Control the content-moderation level for images generated by `gpt-image-1`. Must
|
235
|
+
#
|
236
|
+
# @param n [Integer, nil] The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only
|
237
|
+
#
|
238
|
+
# @param output_compression [Integer, nil] The compression level (0-100%) for the generated images. This parameter is only
|
239
|
+
#
|
240
|
+
# @param output_format [Symbol, OpenAI::Models::ImageGenerateParams::OutputFormat, nil] The format in which the generated images are returned. This parameter is only su
|
241
|
+
#
|
242
|
+
# @param partial_images [Integer, nil] The number of partial images to generate. This parameter is used for
|
243
|
+
#
|
244
|
+
# @param quality [Symbol, OpenAI::Models::ImageGenerateParams::Quality, nil] The quality of the image that will be generated.
|
245
|
+
#
|
246
|
+
# @param response_format [Symbol, OpenAI::Models::ImageGenerateParams::ResponseFormat, nil] The format in which generated images with `dall-e-2` and `dall-e-3` are returned
|
247
|
+
#
|
248
|
+
# @param size [Symbol, OpenAI::Models::ImageGenerateParams::Size, nil] The size of the generated images. Must be one of `1024x1024`, `1536x1024` (lands
|
249
|
+
#
|
250
|
+
# @param style [Symbol, OpenAI::Models::ImageGenerateParams::Style, nil] The style of the generated images. This parameter is only supported for `dall-e-
|
251
|
+
#
|
252
|
+
# @param user [String] A unique identifier representing your end-user, which can help OpenAI to monitor
|
253
|
+
#
|
254
|
+
# @param request_options [OpenAI::RequestOptions, Hash{Symbol=>Object}, nil]
|
255
|
+
#
|
256
|
+
# @return [OpenAI::Internal::Stream<OpenAI::Models::ImageGenPartialImageEvent, OpenAI::Models::ImageGenCompletedEvent>]
|
257
|
+
#
|
258
|
+
# @see OpenAI::Models::ImageGenerateParams
|
259
|
+
def generate_stream_raw(params)
|
260
|
+
parsed, options = OpenAI::ImageGenerateParams.dump_request(params)
|
261
|
+
unless parsed.fetch(:stream, true)
|
262
|
+
message = "Please use `#generate` for the non-streaming use case."
|
263
|
+
raise ArgumentError.new(message)
|
264
|
+
end
|
265
|
+
parsed.store(:stream, true)
|
266
|
+
@client.request(
|
267
|
+
method: :post,
|
268
|
+
path: "images/generations",
|
269
|
+
headers: {"accept" => "text/event-stream"},
|
270
|
+
body: parsed,
|
271
|
+
stream: OpenAI::Internal::Stream,
|
272
|
+
model: OpenAI::ImageGenStreamEvent,
|
273
|
+
options: options
|
274
|
+
)
|
275
|
+
end
|
276
|
+
|
139
277
|
# @api private
|
140
278
|
#
|
141
279
|
# @param client [OpenAI::Client]
|
data/lib/openai/version.rb
CHANGED
data/lib/openai.rb
CHANGED
@@ -320,8 +320,14 @@ require_relative "openai/models/graders/multi_grader"
|
|
320
320
|
require_relative "openai/models/graders/string_check_grader"
|
321
321
|
require_relative "openai/models/image"
|
322
322
|
require_relative "openai/models/image_create_variation_params"
|
323
|
+
require_relative "openai/models/image_edit_completed_event"
|
323
324
|
require_relative "openai/models/image_edit_params"
|
325
|
+
require_relative "openai/models/image_edit_partial_image_event"
|
326
|
+
require_relative "openai/models/image_edit_stream_event"
|
327
|
+
require_relative "openai/models/image_gen_completed_event"
|
324
328
|
require_relative "openai/models/image_generate_params"
|
329
|
+
require_relative "openai/models/image_gen_partial_image_event"
|
330
|
+
require_relative "openai/models/image_gen_stream_event"
|
325
331
|
require_relative "openai/models/image_model"
|
326
332
|
require_relative "openai/models/images_response"
|
327
333
|
require_relative "openai/models/metadata"
|