Skip to content

Commit 9c1c560

Browse files
committed
Enable the stream callback function to get complete chunk information
And do not demand `object: "chat.completion.chunk"` within the chunk object to support not fully OpenAI-compliant services
1 parent 08128b9 commit 9c1c560

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

openai/init.moon

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ parse_chat_response = types.partial {
8383

8484

8585
parse_completion_chunk = types.partial {
86-
object: "chat.completion.chunk"
86+
--object: "chat.completion.chunk"
8787
-- not sure of the whole range of chunks, so for now we strictly parse an append
8888
choices: types.shape {
8989
types.partial {
@@ -190,7 +190,8 @@ class ChatSession
190190

191191
parts = {}
192192
f = @client\create_stream_filter (c) ->
193-
table.insert parts, c.content
193+
if c = parse_completion_chunk c
194+
table.insert parts, c.content
194195

195196
f response
196197
message = {
@@ -250,7 +251,7 @@ class OpenAI
250251
break
251252

252253
accumulation_buffer = rest
253-
if chunk = parse_completion_chunk cjson.decode json_blob
254+
if chunk = cjson.decode json_blob
254255
chunk_callback chunk
255256

256257
...

0 commit comments

Comments
 (0)