Skip to content

Commit b7df81c

Browse files
committed
Update README for streaming
1 parent 58b4003 commit b7df81c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ puts response.dig("choices", 0, "message", "content")
128128

129129
### Streaming ChatGPT
130130

131-
You can stream from the API in realtime, which can be much faster and used to create a more engaging user experience. Pass a [Proc](https://ruby-doc.org/core-2.6/Proc.html) to the `stream` parameter to receive the stream of text chunks as they are generated. Each time an Array of one or more chunks is received, the Proc will be called with the chunks. `ruby-openai` outputs the chunks as an Array of one or more Hashes.
131+
You can stream from the API in realtime, which can be much faster and used to create a more engaging user experience. Pass a [Proc](https://ruby-doc.org/core-2.6/Proc.html) to the `stream` parameter to receive the stream of text chunks as they are generated. Each time one or more chunks is received, the Proc will be called once with each chunk, parsed as a Hash. If OpenAI returns an error, `ruby-openai` will pass that to your proc as a Hash.
132132

133133
```ruby
134134
client.chat(
135135
parameters: {
136136
model: "gpt-3.5-turbo", # Required.
137137
messages: [{ role: "user", content: "Describe a character called Anna!"}], # Required.
138138
temperature: 0.7,
139-
stream: proc do |chunks, _bytesize|
140-
chunks.each { |c| print c.dig("choices", 0, "delta", "content") }
139+
stream: proc do |chunk, _bytesize|
140+
print chunk.dig("choices", 0, "delta", "content")
141141
end
142142
})
143143
# => "Anna is a young woman in her mid-twenties, with wavy chestnut hair that falls to her shoulders..."

0 commit comments

Comments
 (0)