Skip to content

Commit 02e8b1f

Browse files
chore: use generics instead of overloading for sorbet type definitions (#20)
1 parent e5aab92 commit 02e8b1f

File tree

141 files changed

+1009
-1873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+1009
-1873
lines changed

rbi/lib/openai/base_model.rbi

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,11 @@ module OpenAI
171171

172172
abstract!
173173

174+
Value = type_template(:out)
175+
174176
class << self
175177
# All of the valid Symbol values for this enum.
176-
sig { overridable.returns(T::Array[T.any(NilClass, T::Boolean, Integer, Float, Symbol)]) }
178+
sig { overridable.returns(T::Array[Value]) }
177179
def values
178180
end
179181

@@ -220,6 +222,8 @@ module OpenAI
220222

221223
abstract!
222224

225+
Variants = type_template(:out)
226+
223227
class << self
224228
# @api private
225229
#
@@ -229,12 +233,12 @@ module OpenAI
229233
end
230234

231235
# @api private
232-
sig { returns(T::Array[[T.nilable(Symbol), T.anything]]) }
236+
sig { returns(T::Array[[T.nilable(Symbol), Variants]]) }
233237
protected def derefed_variants
234238
end
235239

236240
# All of the specified variants for this union.
237-
sig { overridable.returns(T::Array[T.anything]) }
241+
sig { overridable.returns(T::Array[Variants]) }
238242
def variants
239243
end
240244

@@ -306,6 +310,8 @@ module OpenAI
306310
abstract!
307311
final!
308312

313+
Elem = type_member(:out)
314+
309315
sig(:final) { params(other: T.anything).returns(T::Boolean) }
310316
def ===(other)
311317
end
@@ -342,7 +348,7 @@ module OpenAI
342348
end
343349

344350
# @api private
345-
sig(:final) { returns(OpenAI::Converter::Input) }
351+
sig(:final) { returns(Elem) }
346352
protected def item_type
347353
end
348354

@@ -369,6 +375,8 @@ module OpenAI
369375
abstract!
370376
final!
371377

378+
Elem = type_member(:out)
379+
372380
sig(:final) { params(other: T.anything).returns(T::Boolean) }
373381
def ===(other)
374382
end
@@ -405,7 +413,7 @@ module OpenAI
405413
end
406414

407415
# @api private
408-
sig(:final) { returns(OpenAI::Converter::Input) }
416+
sig(:final) { returns(Elem) }
409417
protected def item_type
410418
end
411419

rbi/lib/openai/models/audio/speech_create_params.rbi

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ module OpenAI
9393
class Model < OpenAI::Union
9494
abstract!
9595

96-
class << self
97-
sig { override.returns([String, Symbol]) }
98-
def variants
99-
end
100-
end
96+
Variants = type_template(:out) { {fixed: T.any(String, Symbol)} }
10197
end
10298

10399
# The voice to use when generating the audio. Supported voices are `alloy`, `ash`,
@@ -107,6 +103,8 @@ module OpenAI
107103
class Voice < OpenAI::Enum
108104
abstract!
109105

106+
Value = type_template(:out) { {fixed: Symbol} }
107+
110108
ALLOY = :alloy
111109
ASH = :ash
112110
CORAL = :coral
@@ -116,31 +114,21 @@ module OpenAI
116114
NOVA = :nova
117115
SAGE = :sage
118116
SHIMMER = :shimmer
119-
120-
class << self
121-
sig { override.returns(T::Array[Symbol]) }
122-
def values
123-
end
124-
end
125117
end
126118

127119
# The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`,
128120
# `wav`, and `pcm`.
129121
class ResponseFormat < OpenAI::Enum
130122
abstract!
131123

124+
Value = type_template(:out) { {fixed: Symbol} }
125+
132126
MP3 = :mp3
133127
OPUS = :opus
134128
AAC = :aac
135129
FLAC = :flac
136130
WAV = :wav
137131
PCM = :pcm
138-
139-
class << self
140-
sig { override.returns(T::Array[Symbol]) }
141-
def values
142-
end
143-
end
144132
end
145133
end
146134
end

rbi/lib/openai/models/audio/speech_model.rbi

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ module OpenAI
66
class SpeechModel < OpenAI::Enum
77
abstract!
88

9+
Value = type_template(:out) { {fixed: Symbol} }
10+
911
TTS_1 = :"tts-1"
1012
TTS_1_HD = :"tts-1-hd"
11-
12-
class << self
13-
sig { override.returns(T::Array[Symbol]) }
14-
def values
15-
end
16-
end
1713
end
1814
end
1915
end

rbi/lib/openai/models/audio/transcription_create_params.rbi

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,16 @@ module OpenAI
134134
class Model < OpenAI::Union
135135
abstract!
136136

137-
class << self
138-
sig { override.returns([String, Symbol]) }
139-
def variants
140-
end
141-
end
137+
Variants = type_template(:out) { {fixed: T.any(String, Symbol)} }
142138
end
143139

144140
class TimestampGranularity < OpenAI::Enum
145141
abstract!
146142

143+
Value = type_template(:out) { {fixed: Symbol} }
144+
147145
WORD = :word
148146
SEGMENT = :segment
149-
150-
class << self
151-
sig { override.returns(T::Array[Symbol]) }
152-
def values
153-
end
154-
end
155147
end
156148
end
157149
end

rbi/lib/openai/models/audio/transcription_create_response.rbi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ module OpenAI
88
class TranscriptionCreateResponse < OpenAI::Union
99
abstract!
1010

11-
class << self
12-
sig { override.returns([OpenAI::Models::Audio::Transcription, OpenAI::Models::Audio::TranscriptionVerbose]) }
13-
def variants
14-
end
15-
end
11+
Variants = type_template(:out) { {fixed: T.any(OpenAI::Models::Audio::Transcription, OpenAI::Models::Audio::TranscriptionVerbose)} }
1612
end
1713
end
1814
end

rbi/lib/openai/models/audio/translation_create_params.rbi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ module OpenAI
9797
class Model < OpenAI::Union
9898
abstract!
9999

100-
class << self
101-
sig { override.returns([String, Symbol]) }
102-
def variants
103-
end
104-
end
100+
Variants = type_template(:out) { {fixed: T.any(String, Symbol)} }
105101
end
106102
end
107103
end

rbi/lib/openai/models/audio/translation_create_response.rbi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ module OpenAI
66
class TranslationCreateResponse < OpenAI::Union
77
abstract!
88

9-
class << self
10-
sig { override.returns([OpenAI::Models::Audio::Translation, OpenAI::Models::Audio::TranslationVerbose]) }
11-
def variants
12-
end
13-
end
9+
Variants = type_template(:out) { {fixed: T.any(OpenAI::Models::Audio::Translation, OpenAI::Models::Audio::TranslationVerbose)} }
1410
end
1511
end
1612
end

rbi/lib/openai/models/audio_model.rbi

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ module OpenAI
55
class AudioModel < OpenAI::Enum
66
abstract!
77

8-
WHISPER_1 = :"whisper-1"
8+
Value = type_template(:out) { {fixed: Symbol} }
99

10-
class << self
11-
sig { override.returns(T::Array[Symbol]) }
12-
def values
13-
end
14-
end
10+
WHISPER_1 = :"whisper-1"
1511
end
1612
end
1713
end

rbi/lib/openai/models/audio_response_format.rbi

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@ module OpenAI
77
class AudioResponseFormat < OpenAI::Enum
88
abstract!
99

10+
Value = type_template(:out) { {fixed: Symbol} }
11+
1012
JSON = :json
1113
TEXT = :text
1214
SRT = :srt
1315
VERBOSE_JSON = :verbose_json
1416
VTT = :vtt
15-
16-
class << self
17-
sig { override.returns(T::Array[Symbol]) }
18-
def values
19-
end
20-
end
2117
end
2218
end
2319
end

rbi/lib/openai/models/batch.rbi

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ module OpenAI
269269
class Status < OpenAI::Enum
270270
abstract!
271271

272+
Value = type_template(:out) { {fixed: Symbol} }
273+
272274
VALIDATING = :validating
273275
FAILED = :failed
274276
IN_PROGRESS = :in_progress
@@ -277,12 +279,6 @@ module OpenAI
277279
EXPIRED = :expired
278280
CANCELLING = :cancelling
279281
CANCELLED = :cancelled
280-
281-
class << self
282-
sig { override.returns(T::Array[Symbol]) }
283-
def values
284-
end
285-
end
286282
end
287283

288284
class Errors < OpenAI::BaseModel

0 commit comments

Comments
 (0)