Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end
We provide support for streaming responses using Server Side Events (SSE).

```ruby
stream = openai.chat_completions_create_streaming(
stream = openai.chat.completions.create_streaming(
messages: [{
role: "user",
content: "Say this is a test"
Expand Down
22 changes: 10 additions & 12 deletions lib/openai/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def try_strict_coerce(value)
# when OpenAI::Models::ChatModel::O1
# # ...
# else
# # ...
# puts(chat_model)
# end
# ```
#
Expand All @@ -320,7 +320,7 @@ def try_strict_coerce(value)
# in :o1
# # ...
# else
# # ...
# puts(chat_model)
# end
# ```
class Enum
Expand Down Expand Up @@ -407,29 +407,27 @@ def try_strict_coerce(value)
# # `chat_completion_content_part` is a `OpenAI::Models::Chat::ChatCompletionContentPart`
# case chat_completion_content_part
# when OpenAI::Models::Chat::ChatCompletionContentPartText
# # ...
# puts(chat_completion_content_part.text)
# when OpenAI::Models::Chat::ChatCompletionContentPartImage
# # ...
# puts(chat_completion_content_part.image_url)
# when OpenAI::Models::Chat::ChatCompletionContentPartInputAudio
# # ...
# puts(chat_completion_content_part.input_audio)
# else
# # ...
# puts(chat_completion_content_part)
# end
# ```
#
# @example
# ```ruby
# case chat_completion_content_part
# in {type: :text, text: text}
# # ...
# puts(text)
# in {type: :image_url, image_url: image_url}
# # ...
# puts(image_url)
# in {type: :input_audio, input_audio: input_audio}
# # ...
# in {type: :file, file: file}
# # ...
# puts(input_audio)
# else
# # ...
# puts(chat_completion_content_part)
# end
# ```
class Union
Expand Down
8 changes: 7 additions & 1 deletion lib/openai/base_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ module OpenAI
#
# @example
# ```ruby
# completions = page.to_enum.take(2)
# completions = page
# .to_enum
# .lazy
# .select { _1.object_id.even? }
# .map(&:itself)
# .take(2)
# .to_a
#
# completions => Array
# ```
Expand Down
14 changes: 10 additions & 4 deletions lib/openai/base_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
module OpenAI
# @example
# ```ruby
# stream.for_each do |message|
# puts(message)
# stream.for_each do |chunk|
# puts(chunk)
# end
# ```
#
# @example
# ```ruby
# messages = stream.to_enum.take(2)
# chunks = stream
# .to_enum
# .lazy
# .select { _1.object_id.even? }
# .map(&:itself)
# .take(2)
# .to_a
#
# messages => Array
# chunks => Array
# ```
module BaseStream
# @return [void]
Expand Down
8 changes: 7 additions & 1 deletion lib/openai/cursor_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ module OpenAI
#
# @example
# ```ruby
# completions = cursor_page.to_enum.take(2)
# completions = cursor_page
# .to_enum
# .lazy
# .select { _1.object_id.even? }
# .map(&:itself)
# .take(2)
# .to_a
#
# completions => Array
# ```
Expand Down
8 changes: 7 additions & 1 deletion lib/openai/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ module OpenAI
#
# @example
# ```ruby
# models = page.to_enum.take(2)
# models = page
# .to_enum
# .lazy
# .select { _1.object_id.even? }
# .map(&:itself)
# .take(2)
# .to_a
#
# models => Array
# ```
Expand Down
14 changes: 10 additions & 4 deletions lib/openai/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
module OpenAI
# @example
# ```ruby
# stream.for_each do |message|
# puts(message)
# stream.for_each do |event|
# puts(event)
# end
# ```
#
# @example
# ```ruby
# messages = stream.to_enum.take(2)
# events = stream
# .to_enum
# .lazy
# .select { _1.object_id.even? }
# .map(&:itself)
# .take(2)
# .to_a
#
# messages => Array
# events => Array
# ```
class Stream
include OpenAI::BaseStream
Expand Down