Skip to content

Commit 3c56d25

Browse files
committed
Even stricter
1 parent 90ca293 commit 3c56d25

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

openai/init.moon

+6-3
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)