@@ -3027,6 +3027,7 @@ async def non_streaming_chat_response_handler(response, ctx):
30273027 metadata ['chat_id' ],
30283028 metadata ['message_id' ],
30293029 {
3030+ 'done' : True ,
30303031 'role' : 'assistant' ,
30313032 'content' : content ,
30323033 'output' : response_output ,
@@ -4376,6 +4377,7 @@ def restricted_import(name, globals=None, locals=None, fromlist=(), level=0):
43764377 metadata ['chat_id' ],
43774378 metadata ['message_id' ],
43784379 {
4380+ 'done' : True ,
43794381 'content' : serialize_output (output ),
43804382 'output' : output ,
43814383 ** ({'usage' : usage } if usage else {}),
@@ -4385,7 +4387,13 @@ def restricted_import(name, globals=None, locals=None, fromlist=(), level=0):
43854387 Chats .upsert_message_to_chat_by_id_and_message_id (
43864388 metadata ['chat_id' ],
43874389 metadata ['message_id' ],
4388- {'usage' : usage },
4390+ {'done' : True , 'usage' : usage },
4391+ )
4392+ else :
4393+ Chats .upsert_message_to_chat_by_id_and_message_id (
4394+ metadata ['chat_id' ],
4395+ metadata ['message_id' ],
4396+ {'done' : True },
43894397 )
43904398
43914399 # Send a webhook notification if the user is not active
@@ -4422,10 +4430,17 @@ def restricted_import(name, globals=None, locals=None, fromlist=(), level=0):
44224430 metadata ['chat_id' ],
44234431 metadata ['message_id' ],
44244432 {
4433+ 'done' : True ,
44254434 'content' : serialize_output (output ),
44264435 'output' : output ,
44274436 },
44284437 )
4438+ else :
4439+ Chats .upsert_message_to_chat_by_id_and_message_id (
4440+ metadata ['chat_id' ],
4441+ metadata ['message_id' ],
4442+ {'done' : True },
4443+ )
44294444
44304445 if response .background is not None :
44314446 await response .background ()
0 commit comments