File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -215,12 +215,14 @@ class OpenAI
215215 create_stream_filter : ( chunk_callback) =>
216216 assert types. function( chunk_callback) , " Must provide chunk_callback function when streaming response"
217217
218- accumulation_buffer = " "
218+ accumulation_buffer, streamed = " "
219219
220220 ( ... ) ->
221221 chunk = ...
222222
223- if type ( chunk) == " string"
223+ if chunk == nil
224+ assert not streamed or accumulation_buffer\ match" ^%s*$" , " buffer not empty"
225+ elseif type ( chunk) == " string"
224226 accumulation_buffer ..= chunk
225227
226228 while true
@@ -233,8 +235,9 @@ class OpenAI
233235 field, value, rest_evt = event\ match " ^(.-):%s+([^\r\n ]+)(.-)$"
234236 switch field
235237 when " data"
238+ streamed = true
236239 unless value== " [DONE]"
237- chunk_callback ( json . decode value)
240+ chunk_callback ( cjson . decode value)
238241 when " event" , " id" , " retry" , " " -- comment
239242 nil -- noop
240243 when nil
You can’t perform that action at this time.
0 commit comments