Skip to content

Commit 2114add

Browse files
feat(api): manual updates
1 parent 5d6cc1e commit 2114add

39 files changed

+3207
-12
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 109
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-c7dacca97e28bceff218684bb429481a70aa47aadad983ed9178bfda75ff4cd2.yml
3-
openapi_spec_hash: 28eb1bb901ca10d2e37db4606d2bcfa7
4-
config_hash: 167ad0ca036d0f023c78e6496b4311e8
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-670ea0d2cc44f52a87dd3cadea45632953283e0636ba30788fdbdb22a232ccac.yml
3+
openapi_spec_hash: d8b7d38911fead545adf3e4297956410
4+
config_hash: 5525bda35e48ea6387c6175c4d1651fa

examples/image_stream.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
# typed: strong
4+
5+
require_relative "../lib/openai"
6+
require "base64"
7+
8+
client = OpenAI::Client.new
9+
10+
puts "Starting image streaming example..."
11+
12+
stream = client.images.generate_stream_raw(
13+
model: "gpt-image-1",
14+
prompt: "A cute baby sea otter",
15+
n: 1,
16+
size: "1024x1024",
17+
partial_images: 3
18+
)
19+
20+
stream.each do |event|
21+
case event
22+
when OpenAI::Models::ImageGenPartialImageEvent
23+
puts(" Partial image #{event.partial_image_index + 1}/3 received")
24+
puts(" Size: #{event.b64_json.length} characters (base64)")
25+
26+
# Save partial image to file
27+
filename = "partial_#{event.partial_image_index + 1}.png"
28+
image_data = Base64.decode64(event.b64_json)
29+
File.write(filename, image_data)
30+
puts(" Saved to: #{File.expand_path(filename)}")
31+
32+
when OpenAI::Models::ImageGenCompletedEvent
33+
puts("\n✅ Final image completed!")
34+
puts(" Size: #{event.b64_json.length} characters (base64)")
35+
36+
# Save final image to file
37+
filename = "final_image.png"
38+
image_data = Base64.decode64(event.b64_json)
39+
File.write(filename, image_data)
40+
puts(" Saved to: #{File.expand_path(filename)}")
41+
end
42+
end
43+
44+
puts "Image streaming completed!"

lib/openai.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,14 @@
320320
require_relative "openai/models/graders/string_check_grader"
321321
require_relative "openai/models/image"
322322
require_relative "openai/models/image_create_variation_params"
323+
require_relative "openai/models/image_edit_completed_event"
323324
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"
324328
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"
325331
require_relative "openai/models/image_model"
326332
require_relative "openai/models/images_response"
327333
require_relative "openai/models/metadata"

lib/openai/models.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,22 @@ module OpenAI
152152

153153
ImageCreateVariationParams = OpenAI::Models::ImageCreateVariationParams
154154

155+
ImageEditCompletedEvent = OpenAI::Models::ImageEditCompletedEvent
156+
155157
ImageEditParams = OpenAI::Models::ImageEditParams
156158

159+
ImageEditPartialImageEvent = OpenAI::Models::ImageEditPartialImageEvent
160+
161+
ImageEditStreamEvent = OpenAI::Models::ImageEditStreamEvent
162+
163+
ImageGenCompletedEvent = OpenAI::Models::ImageGenCompletedEvent
164+
157165
ImageGenerateParams = OpenAI::Models::ImageGenerateParams
158166

167+
ImageGenPartialImageEvent = OpenAI::Models::ImageGenPartialImageEvent
168+
169+
ImageGenStreamEvent = OpenAI::Models::ImageGenStreamEvent
170+
159171
ImageModel = OpenAI::Models::ImageModel
160172

161173
ImagesResponse = OpenAI::Models::ImagesResponse
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# frozen_string_literal: true
2+
3+
module OpenAI
4+
module Models
5+
class ImageEditCompletedEvent < OpenAI::Internal::Type::BaseModel
6+
# @!attribute b64_json
7+
# Base64-encoded final edited 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 edited image.
14+
#
15+
# @return [Symbol, OpenAI::Models::ImageEditCompletedEvent::Background]
16+
required :background, enum: -> { OpenAI::ImageEditCompletedEvent::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 edited image.
26+
#
27+
# @return [Symbol, OpenAI::Models::ImageEditCompletedEvent::OutputFormat]
28+
required :output_format, enum: -> { OpenAI::ImageEditCompletedEvent::OutputFormat }
29+
30+
# @!attribute quality
31+
# The quality setting for the edited image.
32+
#
33+
# @return [Symbol, OpenAI::Models::ImageEditCompletedEvent::Quality]
34+
required :quality, enum: -> { OpenAI::ImageEditCompletedEvent::Quality }
35+
36+
# @!attribute size
37+
# The size of the edited image.
38+
#
39+
# @return [Symbol, OpenAI::Models::ImageEditCompletedEvent::Size]
40+
required :size, enum: -> { OpenAI::ImageEditCompletedEvent::Size }
41+
42+
# @!attribute type
43+
# The type of the event. Always `image_edit.completed`.
44+
#
45+
# @return [Symbol, :"image_edit.completed"]
46+
required :type, const: :"image_edit.completed"
47+
48+
# @!attribute usage
49+
# For `gpt-image-1` only, the token usage information for the image generation.
50+
#
51+
# @return [OpenAI::Models::ImageEditCompletedEvent::Usage]
52+
required :usage, -> { OpenAI::ImageEditCompletedEvent::Usage }
53+
54+
# @!method initialize(b64_json:, background:, created_at:, output_format:, quality:, size:, usage:, type: :"image_edit.completed")
55+
# Some parameter documentations has been truncated, see
56+
# {OpenAI::Models::ImageEditCompletedEvent} for more details.
57+
#
58+
# Emitted when image editing has completed and the final image is available.
59+
#
60+
# @param b64_json [String] Base64-encoded final edited image data, suitable for rendering as an image.
61+
#
62+
# @param background [Symbol, OpenAI::Models::ImageEditCompletedEvent::Background] The background setting for the edited image.
63+
#
64+
# @param created_at [Integer] The Unix timestamp when the event was created.
65+
#
66+
# @param output_format [Symbol, OpenAI::Models::ImageEditCompletedEvent::OutputFormat] The output format for the edited image.
67+
#
68+
# @param quality [Symbol, OpenAI::Models::ImageEditCompletedEvent::Quality] The quality setting for the edited image.
69+
#
70+
# @param size [Symbol, OpenAI::Models::ImageEditCompletedEvent::Size] The size of the edited image.
71+
#
72+
# @param usage [OpenAI::Models::ImageEditCompletedEvent::Usage] For `gpt-image-1` only, the token usage information for the image generation.
73+
#
74+
# @param type [Symbol, :"image_edit.completed"] The type of the event. Always `image_edit.completed`.
75+
76+
# The background setting for the edited image.
77+
#
78+
# @see OpenAI::Models::ImageEditCompletedEvent#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 edited image.
91+
#
92+
# @see OpenAI::Models::ImageEditCompletedEvent#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 edited image.
105+
#
106+
# @see OpenAI::Models::ImageEditCompletedEvent#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 edited image.
120+
#
121+
# @see OpenAI::Models::ImageEditCompletedEvent#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+
134+
# @see OpenAI::Models::ImageEditCompletedEvent#usage
135+
class Usage < OpenAI::Internal::Type::BaseModel
136+
# @!attribute input_tokens
137+
# The number of tokens (images and text) in the input prompt.
138+
#
139+
# @return [Integer]
140+
required :input_tokens, Integer
141+
142+
# @!attribute input_tokens_details
143+
# The input tokens detailed information for the image generation.
144+
#
145+
# @return [OpenAI::Models::ImageEditCompletedEvent::Usage::InputTokensDetails]
146+
required :input_tokens_details, -> { OpenAI::ImageEditCompletedEvent::Usage::InputTokensDetails }
147+
148+
# @!attribute output_tokens
149+
# The number of image tokens in the output image.
150+
#
151+
# @return [Integer]
152+
required :output_tokens, Integer
153+
154+
# @!attribute total_tokens
155+
# The total number of tokens (images and text) used for the image generation.
156+
#
157+
# @return [Integer]
158+
required :total_tokens, Integer
159+
160+
# @!method initialize(input_tokens:, input_tokens_details:, output_tokens:, total_tokens:)
161+
# Some parameter documentations has been truncated, see
162+
# {OpenAI::Models::ImageEditCompletedEvent::Usage} for more details.
163+
#
164+
# For `gpt-image-1` only, the token usage information for the image generation.
165+
#
166+
# @param input_tokens [Integer] The number of tokens (images and text) in the input prompt.
167+
#
168+
# @param input_tokens_details [OpenAI::Models::ImageEditCompletedEvent::Usage::InputTokensDetails] The input tokens detailed information for the image generation.
169+
#
170+
# @param output_tokens [Integer] The number of image tokens in the output image.
171+
#
172+
# @param total_tokens [Integer] The total number of tokens (images and text) used for the image generation.
173+
174+
# @see OpenAI::Models::ImageEditCompletedEvent::Usage#input_tokens_details
175+
class InputTokensDetails < OpenAI::Internal::Type::BaseModel
176+
# @!attribute image_tokens
177+
# The number of image tokens in the input prompt.
178+
#
179+
# @return [Integer]
180+
required :image_tokens, Integer
181+
182+
# @!attribute text_tokens
183+
# The number of text tokens in the input prompt.
184+
#
185+
# @return [Integer]
186+
required :text_tokens, Integer
187+
188+
# @!method initialize(image_tokens:, text_tokens:)
189+
# The input tokens detailed information for the image generation.
190+
#
191+
# @param image_tokens [Integer] The number of image tokens in the input prompt.
192+
#
193+
# @param text_tokens [Integer] The number of text tokens in the input prompt.
194+
end
195+
end
196+
end
197+
end
198+
end

lib/openai/models/image_edit_params.rb

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module OpenAI
44
module Models
55
# @see OpenAI::Resources::Images#edit
6+
#
7+
# @see OpenAI::Resources::Images#stream_raw
68
class ImageEditParams < OpenAI::Internal::Type::BaseModel
79
extend OpenAI::Internal::Type::RequestParameters::Converter
810
include OpenAI::Internal::Type::RequestParameters
@@ -38,6 +40,14 @@ class ImageEditParams < OpenAI::Internal::Type::BaseModel
3840
# @return [Symbol, OpenAI::Models::ImageEditParams::Background, nil]
3941
optional :background, enum: -> { OpenAI::ImageEditParams::Background }, nil?: true
4042

43+
# @!attribute input_fidelity
44+
# Control how much effort the model will exert to match the style and features,
45+
# especially facial features, of input images. This parameter is only supported
46+
# for `gpt-image-1`. Supports `high` and `low`. Defaults to `low`.
47+
#
48+
# @return [Symbol, OpenAI::Models::ImageEditParams::InputFidelity, nil]
49+
optional :input_fidelity, enum: -> { OpenAI::ImageEditParams::InputFidelity }, nil?: true
50+
4151
# @!attribute mask
4252
# An additional image whose fully transparent areas (e.g. where alpha is zero)
4353
# indicate where `image` should be edited. If there are multiple images provided,
@@ -77,6 +87,14 @@ class ImageEditParams < OpenAI::Internal::Type::BaseModel
7787
# @return [Symbol, OpenAI::Models::ImageEditParams::OutputFormat, nil]
7888
optional :output_format, enum: -> { OpenAI::ImageEditParams::OutputFormat }, nil?: true
7989

90+
# @!attribute partial_images
91+
# The number of partial images to generate. This parameter is used for streaming
92+
# responses that return partial images. Value must be between 0 and 3. When set to
93+
# 0, the response will be a single image sent in one streaming event.
94+
#
95+
# @return [Integer, nil]
96+
optional :partial_images, Integer, nil?: true
97+
8098
# @!attribute quality
8199
# The quality of the image that will be generated. `high`, `medium` and `low` are
82100
# only supported for `gpt-image-1`. `dall-e-2` only supports `standard` quality.
@@ -110,7 +128,7 @@ class ImageEditParams < OpenAI::Internal::Type::BaseModel
110128
# @return [String, nil]
111129
optional :user, String
112130

113-
# @!method initialize(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: {})
131+
# @!method initialize(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: {})
114132
# Some parameter documentations has been truncated, see
115133
# {OpenAI::Models::ImageEditParams} for more details.
116134
#
@@ -120,6 +138,8 @@ class ImageEditParams < OpenAI::Internal::Type::BaseModel
120138
#
121139
# @param background [Symbol, OpenAI::Models::ImageEditParams::Background, nil] Allows to set transparency for the background of the generated image(s).
122140
#
141+
# @param input_fidelity [Symbol, OpenAI::Models::ImageEditParams::InputFidelity, nil] Control how much effort the model will exert to match the style and features,
142+
#
123143
# @param mask [Pathname, StringIO, IO, String, OpenAI::FilePart] An additional image whose fully transparent areas (e.g. where alpha is zero) ind
124144
#
125145
# @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
@@ -130,6 +150,8 @@ class ImageEditParams < OpenAI::Internal::Type::BaseModel
130150
#
131151
# @param output_format [Symbol, OpenAI::Models::ImageEditParams::OutputFormat, nil] The format in which the generated images are returned. This parameter is
132152
#
153+
# @param partial_images [Integer, nil] The number of partial images to generate. This parameter is used for
154+
#
133155
# @param quality [Symbol, OpenAI::Models::ImageEditParams::Quality, nil] The quality of the image that will be generated. `high`, `medium` and `low` are
134156
#
135157
# @param response_format [Symbol, OpenAI::Models::ImageEditParams::ResponseFormat, nil] The format in which the generated images are returned. Must be one of `url` or `
@@ -179,6 +201,19 @@ module Background
179201
# @return [Array<Symbol>]
180202
end
181203

204+
# Control how much effort the model will exert to match the style and features,
205+
# especially facial features, of input images. This parameter is only supported
206+
# for `gpt-image-1`. Supports `high` and `low`. Defaults to `low`.
207+
module InputFidelity
208+
extend OpenAI::Internal::Type::Enum
209+
210+
HIGH = :high
211+
LOW = :low
212+
213+
# @!method self.values
214+
# @return [Array<Symbol>]
215+
end
216+
182217
# The model to use for image generation. Only `dall-e-2` and `gpt-image-1` are
183218
# supported. Defaults to `dall-e-2` unless a parameter specific to `gpt-image-1`
184219
# is used.

0 commit comments

Comments
 (0)