From dc258e3b9b01e9d3ccb6fbd7d30f6f6bbc539e48 Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Fri, 14 Mar 2025 05:19:39 +0000 Subject: [PATCH] chore: touch up sdk usage examples --- README.md | 2 +- lib/openai/base_model.rb | 22 ++++++++++------------ lib/openai/base_page.rb | 8 +++++++- lib/openai/base_stream.rb | 14 ++++++++++---- lib/openai/cursor_page.rb | 8 +++++++- lib/openai/page.rb | 8 +++++++- lib/openai/stream.rb | 14 ++++++++++---- 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index c5e359bc..8b458397 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/lib/openai/base_model.rb b/lib/openai/base_model.rb index 3abd2ca3..09b3d852 100644 --- a/lib/openai/base_model.rb +++ b/lib/openai/base_model.rb @@ -306,7 +306,7 @@ def try_strict_coerce(value) # when OpenAI::Models::ChatModel::O1 # # ... # else - # # ... + # puts(chat_model) # end # ``` # @@ -320,7 +320,7 @@ def try_strict_coerce(value) # in :o1 # # ... # else - # # ... + # puts(chat_model) # end # ``` class Enum @@ -407,13 +407,13 @@ 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 # ``` # @@ -421,15 +421,13 @@ def try_strict_coerce(value) # ```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 diff --git a/lib/openai/base_page.rb b/lib/openai/base_page.rb index 481df2ea..c7489dfe 100644 --- a/lib/openai/base_page.rb +++ b/lib/openai/base_page.rb @@ -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 # ``` diff --git a/lib/openai/base_stream.rb b/lib/openai/base_stream.rb index 2aef50fe..59f8f874 100644 --- a/lib/openai/base_stream.rb +++ b/lib/openai/base_stream.rb @@ -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] diff --git a/lib/openai/cursor_page.rb b/lib/openai/cursor_page.rb index 7773eb35..9ee3cd79 100644 --- a/lib/openai/cursor_page.rb +++ b/lib/openai/cursor_page.rb @@ -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 # ``` diff --git a/lib/openai/page.rb b/lib/openai/page.rb index 0d0866e7..55b56fe4 100644 --- a/lib/openai/page.rb +++ b/lib/openai/page.rb @@ -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 # ``` diff --git a/lib/openai/stream.rb b/lib/openai/stream.rb index f6f0b113..2d448ef0 100644 --- a/lib/openai/stream.rb +++ b/lib/openai/stream.rb @@ -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