File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -219,11 +219,14 @@ class OpenAI
219219 assert types. function( chunk_callback) , " Must provide chunk_callback function when streaming response"
220220
221221 accumulation_buffer = " "
222+ streamed = false
222223
223224 ( ... ) ->
224225 chunk = ...
225226
226- if type ( chunk) == " string"
227+ if chunk == nil
228+ assert not streamed or accumulation_buffer\ match" ^%s*$" , " buffer not empty"
229+ elseif type ( chunk) == " string"
227230 accumulation_buffer ..= chunk
228231
229232 while true
@@ -236,8 +239,9 @@ class OpenAI
236239 field, value, rest_evt = event\ match " ^(.-):%s+([^\r\n ]+)(.-)$"
237240 switch field
238241 when " data"
242+ streamed = true
239243 unless value== " [DONE]"
240- chunk_callback ( json . decode value)
244+ chunk_callback ( cjson . decode value)
241245 when " event" , " id" , " retry" , " " -- comment
242246 nil -- noop
243247 when nil
You can’t perform that action at this time.
0 commit comments