Skip to content

Commit a4d8ab8

Browse files
committed
relax chunk parsing and fail on other chunks that fail to parse (fix for ollama)
1 parent 7ac8a5e commit a4d8ab8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

openai/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ local parse_completion_chunk = types.partial({
6767
object = "chat.completion.chunk",
6868
choices = types.shape({
6969
types.partial({
70-
delta = types.shape({
70+
delta = types.partial({
7171
["content"] = types.string:tag("content")
7272
}),
7373
index = types.number:tag("index")
@@ -243,7 +243,7 @@ do
243243
end
244244
accumulation_buffer = rest
245245
do
246-
chunk = parse_completion_chunk(cjson.decode(json_blob))
246+
chunk = assert(parse_completion_chunk(cjson.decode(json_blob)))
247247
if chunk then
248248
chunk_callback(chunk)
249249
end

openai/init.moon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ parse_completion_chunk = types.partial {
8989
-- not sure of the whole range of chunks, so for now we strictly parse an append
9090
choices: types.shape {
9191
types.partial {
92-
delta: types.shape {
92+
delta: types.partial {
9393
"content": types.string\tag "content"
9494
}
9595
index: types.number\tag "index"
@@ -253,7 +253,7 @@ class OpenAI
253253
break
254254

255255
accumulation_buffer = rest
256-
if chunk = parse_completion_chunk cjson.decode json_blob
256+
if chunk = assert parse_completion_chunk cjson.decode json_blob
257257
chunk_callback chunk
258258

259259
...

0 commit comments

Comments
 (0)