File tree Expand file tree Collapse file tree 7 files changed +52
-24
lines changed Expand file tree Collapse file tree 7 files changed +52
-24
lines changed Original file line number Diff line number Diff line change 73
73
We provide support for streaming responses using Server Side Events (SSE).
74
74
75
75
``` ruby
76
- stream = openai.chat_completions_create_streaming (
76
+ stream = openai.chat.completions.create_streaming (
77
77
messages: [{
78
78
role: " user" ,
79
79
content: " Say this is a test"
Original file line number Diff line number Diff line change @@ -306,7 +306,7 @@ def try_strict_coerce(value)
306
306
# when OpenAI::Models::ChatModel::O1
307
307
# # ...
308
308
# else
309
- # # ...
309
+ # puts(chat_model)
310
310
# end
311
311
# ```
312
312
#
@@ -320,7 +320,7 @@ def try_strict_coerce(value)
320
320
# in :o1
321
321
# # ...
322
322
# else
323
- # # ...
323
+ # puts(chat_model)
324
324
# end
325
325
# ```
326
326
class Enum
@@ -407,29 +407,27 @@ def try_strict_coerce(value)
407
407
# # `chat_completion_content_part` is a `OpenAI::Models::Chat::ChatCompletionContentPart`
408
408
# case chat_completion_content_part
409
409
# when OpenAI::Models::Chat::ChatCompletionContentPartText
410
- # # ...
410
+ # puts(chat_completion_content_part.text)
411
411
# when OpenAI::Models::Chat::ChatCompletionContentPartImage
412
- # # ...
412
+ # puts(chat_completion_content_part.image_url)
413
413
# when OpenAI::Models::Chat::ChatCompletionContentPartInputAudio
414
- # # ...
414
+ # puts(chat_completion_content_part.input_audio)
415
415
# else
416
- # # ...
416
+ # puts(chat_completion_content_part)
417
417
# end
418
418
# ```
419
419
#
420
420
# @example
421
421
# ```ruby
422
422
# case chat_completion_content_part
423
423
# in {type: :text, text: text}
424
- # # ...
424
+ # puts(text)
425
425
# in {type: :image_url, image_url: image_url}
426
- # # ...
426
+ # puts(image_url)
427
427
# in {type: :input_audio, input_audio: input_audio}
428
- # # ...
429
- # in {type: :file, file: file}
430
- # # ...
428
+ # puts(input_audio)
431
429
# else
432
- # # ...
430
+ # puts(chat_completion_content_part)
433
431
# end
434
432
# ```
435
433
class Union
Original file line number Diff line number Diff line change @@ -19,7 +19,13 @@ module OpenAI
19
19
#
20
20
# @example
21
21
# ```ruby
22
- # completions = page.to_enum.take(2)
22
+ # completions = page
23
+ # .to_enum
24
+ # .lazy
25
+ # .select { _1.object_id.even? }
26
+ # .map(&:itself)
27
+ # .take(2)
28
+ # .to_a
23
29
#
24
30
# completions => Array
25
31
# ```
Original file line number Diff line number Diff line change 3
3
module OpenAI
4
4
# @example
5
5
# ```ruby
6
- # stream.for_each do |message |
7
- # puts(message )
6
+ # stream.for_each do |chunk |
7
+ # puts(chunk )
8
8
# end
9
9
# ```
10
10
#
11
11
# @example
12
12
# ```ruby
13
- # messages = stream.to_enum.take(2)
13
+ # chunks = stream
14
+ # .to_enum
15
+ # .lazy
16
+ # .select { _1.object_id.even? }
17
+ # .map(&:itself)
18
+ # .take(2)
19
+ # .to_a
14
20
#
15
- # messages => Array
21
+ # chunks => Array
16
22
# ```
17
23
module BaseStream
18
24
# @return [void]
Original file line number Diff line number Diff line change @@ -17,7 +17,13 @@ module OpenAI
17
17
#
18
18
# @example
19
19
# ```ruby
20
- # completions = cursor_page.to_enum.take(2)
20
+ # completions = cursor_page
21
+ # .to_enum
22
+ # .lazy
23
+ # .select { _1.object_id.even? }
24
+ # .map(&:itself)
25
+ # .take(2)
26
+ # .to_a
21
27
#
22
28
# completions => Array
23
29
# ```
Original file line number Diff line number Diff line change @@ -17,7 +17,13 @@ module OpenAI
17
17
#
18
18
# @example
19
19
# ```ruby
20
- # models = page.to_enum.take(2)
20
+ # models = page
21
+ # .to_enum
22
+ # .lazy
23
+ # .select { _1.object_id.even? }
24
+ # .map(&:itself)
25
+ # .take(2)
26
+ # .to_a
21
27
#
22
28
# models => Array
23
29
# ```
Original file line number Diff line number Diff line change 3
3
module OpenAI
4
4
# @example
5
5
# ```ruby
6
- # stream.for_each do |message |
7
- # puts(message )
6
+ # stream.for_each do |event |
7
+ # puts(event )
8
8
# end
9
9
# ```
10
10
#
11
11
# @example
12
12
# ```ruby
13
- # messages = stream.to_enum.take(2)
13
+ # events = stream
14
+ # .to_enum
15
+ # .lazy
16
+ # .select { _1.object_id.even? }
17
+ # .map(&:itself)
18
+ # .take(2)
19
+ # .to_a
14
20
#
15
- # messages => Array
21
+ # events => Array
16
22
# ```
17
23
class Stream
18
24
include OpenAI ::BaseStream
You can’t perform that action at this time.
0 commit comments