File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -313,6 +313,7 @@ async def completion_stream_generator(
313
313
else :
314
314
include_usage , include_continuous_usage = False , False
315
315
316
+ chunk = None
316
317
try :
317
318
async for prompt_idx , res in result_generator :
318
319
prompt_token_ids = res .prompt_token_ids
@@ -441,6 +442,12 @@ async def completion_stream_generator(
441
442
choices = [],
442
443
usage = final_usage_info ,
443
444
)
445
+
446
+ # if accumulate, send the usage info attached to last chunk instead
447
+ if request .accumulate and chunk is not None :
448
+ chunk .usage = final_usage_info
449
+ final_usage_chunk = chunk
450
+
444
451
final_usage_data = (final_usage_chunk .model_dump_json (
445
452
exclude_unset = False , exclude_none = True ))
446
453
yield f"data: { final_usage_data } \n \n "
You can’t perform that action at this time.
0 commit comments