Skip to content

Commit c2a48b0

Browse files
chore: touch up sdk usage examples (#14)
1 parent bb610d1 commit c2a48b0

File tree

7 files changed

+52
-24
lines changed

7 files changed

+52
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ end
7373
We provide support for streaming responses using Server Side Events (SSE).
7474

7575
```ruby
76-
stream = openai.chat_completions_create_streaming(
76+
stream = openai.chat.completions.create_streaming(
7777
messages: [{
7878
role: "user",
7979
content: "Say this is a test"

lib/openai/base_model.rb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def try_strict_coerce(value)
306306
# when OpenAI::Models::ChatModel::O1
307307
# # ...
308308
# else
309-
# # ...
309+
# puts(chat_model)
310310
# end
311311
# ```
312312
#
@@ -320,7 +320,7 @@ def try_strict_coerce(value)
320320
# in :o1
321321
# # ...
322322
# else
323-
# # ...
323+
# puts(chat_model)
324324
# end
325325
# ```
326326
class Enum
@@ -407,29 +407,27 @@ def try_strict_coerce(value)
407407
# # `chat_completion_content_part` is a `OpenAI::Models::Chat::ChatCompletionContentPart`
408408
# case chat_completion_content_part
409409
# when OpenAI::Models::Chat::ChatCompletionContentPartText
410-
# # ...
410+
# puts(chat_completion_content_part.text)
411411
# when OpenAI::Models::Chat::ChatCompletionContentPartImage
412-
# # ...
412+
# puts(chat_completion_content_part.image_url)
413413
# when OpenAI::Models::Chat::ChatCompletionContentPartInputAudio
414-
# # ...
414+
# puts(chat_completion_content_part.input_audio)
415415
# else
416-
# # ...
416+
# puts(chat_completion_content_part)
417417
# end
418418
# ```
419419
#
420420
# @example
421421
# ```ruby
422422
# case chat_completion_content_part
423423
# in {type: :text, text: text}
424-
# # ...
424+
# puts(text)
425425
# in {type: :image_url, image_url: image_url}
426-
# # ...
426+
# puts(image_url)
427427
# in {type: :input_audio, input_audio: input_audio}
428-
# # ...
429-
# in {type: :file, file: file}
430-
# # ...
428+
# puts(input_audio)
431429
# else
432-
# # ...
430+
# puts(chat_completion_content_part)
433431
# end
434432
# ```
435433
class Union

lib/openai/base_page.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ module OpenAI
1919
#
2020
# @example
2121
# ```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
2329
#
2430
# completions => Array
2531
# ```

lib/openai/base_stream.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
module OpenAI
44
# @example
55
# ```ruby
6-
# stream.for_each do |message|
7-
# puts(message)
6+
# stream.for_each do |chunk|
7+
# puts(chunk)
88
# end
99
# ```
1010
#
1111
# @example
1212
# ```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
1420
#
15-
# messages => Array
21+
# chunks => Array
1622
# ```
1723
module BaseStream
1824
# @return [void]

lib/openai/cursor_page.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ module OpenAI
1717
#
1818
# @example
1919
# ```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
2127
#
2228
# completions => Array
2329
# ```

lib/openai/page.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ module OpenAI
1717
#
1818
# @example
1919
# ```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
2127
#
2228
# models => Array
2329
# ```

lib/openai/stream.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
module OpenAI
44
# @example
55
# ```ruby
6-
# stream.for_each do |message|
7-
# puts(message)
6+
# stream.for_each do |event|
7+
# puts(event)
88
# end
99
# ```
1010
#
1111
# @example
1212
# ```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
1420
#
15-
# messages => Array
21+
# events => Array
1622
# ```
1723
class Stream
1824
include OpenAI::BaseStream

0 commit comments

Comments
 (0)