@@ -140,8 +140,9 @@ create_chat_stream_filter = (chunk_callback) ->
140140 break
141141
142142 accumulation_buffer = rest
143- if chunk = parse_completion_chunk cjson. decode json_blob
144- chunk_callback chunk
143+ chunk_callback cjson. decode json_blob
144+ -- if chunk = parse_completion_chunk cjson.decode json_blob
145+ -- chunk_callback chunk
145146
146147 ...
147148
@@ -186,7 +187,7 @@ class ChatSession
186187 -- append_response: should the response be appended to the chat history
187188 -- stream_callback: provide a function to enable streaming output. function will receive each chunk as it's generated
188189 generate_response : ( append_response= true , stream_callback= nil ) =>
189- status, response = @client \ create_chat_completion @messages , {
190+ status, response = @client \ chat @messages , {
190191 function_call : @opts . function_call -- override the default function call behavior
191192 functions : @functions
192193 model : @opts . model
@@ -214,7 +215,8 @@ class ChatSession
214215
215216 parts = {}
216217 f = create_chat_stream_filter ( c) ->
217- table.insert parts, c. content
218+ if parsed = parse_completion_chunk c
219+ table.insert parts, parsed. content
218220
219221 f response
220222 message = {
@@ -250,4 +252,5 @@ class ChatSession
250252 : ChatSession
251253 : test_message
252254 : create_chat_stream_filter
255+ : parse_completion_chunk
253256}
0 commit comments