refactor: move background tasks handler call to ensure consistent execution in chat response handlers (#24717)
This commit is contained in:
1 parent
974b13839e
commit
80da840ae5
1 file changed
+2
-2
@@ -3545,13 +3545,13 @@ async def non_streaming_chat_response_handler(response, ctx):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
await background_tasks_handler(ctx)
|
|
||||||
ctx['assistant_message'] = {
|
ctx['assistant_message'] = {
|
||||||
'content': content,
|
'content': content,
|
||||||
'output': response_output,
|
'output': response_output,
|
||||||
**({'usage': usage} if usage else {}),
|
**({'usage': usage} if usage else {}),
|
||||||
}
|
}
|
||||||
await outlet_filter_handler(ctx)
|
await outlet_filter_handler(ctx)
|
||||||
|
await background_tasks_handler(ctx)
|
||||||
|
|
||||||
response = build_response_object(response, merge_events_into_response(response_data, events))
|
response = build_response_object(response, merge_events_into_response(response_data, events))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -5164,13 +5164,13 @@ async def streaming_chat_response_handler(response, ctx):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
await background_tasks_handler(ctx)
|
|
||||||
ctx['assistant_message'] = {
|
ctx['assistant_message'] = {
|
||||||
'content': serialize_output(output),
|
'content': serialize_output(output),
|
||||||
'output': output,
|
'output': output,
|
||||||
**({'usage': usage} if usage else {}),
|
**({'usage': usage} if usage else {}),
|
||||||
}
|
}
|
||||||
await outlet_filter_handler(ctx)
|
await outlet_filter_handler(ctx)
|
||||||
|
await background_tasks_handler(ctx)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
log.warning('Task was cancelled!')
|
log.warning('Task was cancelled!')
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user