Skip to content

Commit 1836199

Browse files
committed
Even stricter
1 parent 3a05a89 commit 1836199

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

openai/init.moon

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

0 commit comments

Comments
 (0)