mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-05 02:41:34 +00:00
Merge 77ad55a581 into 4ef7e35b88
This commit is contained in:
commit
bbe5d0183e
1 changed files with 14 additions and 1 deletions
|
|
@ -6640,6 +6640,7 @@ async def streaming_chat_response_handler(response, ctx):
|
|||
|
||||
try:
|
||||
assistant_message = {}
|
||||
outlet_task = None
|
||||
filter_context = FilterContext()
|
||||
has_api_outlet_filters = ENABLE_API_OUTLET_FILTERS and bool(filter_functions)
|
||||
if ENABLE_API_OUTLET_FILTERS and not has_api_outlet_filters:
|
||||
|
|
@ -6690,9 +6691,21 @@ async def streaming_chat_response_handler(response, ctx):
|
|||
if data:
|
||||
if has_api_outlet_filters:
|
||||
update_assistant_message_from_stream(assistant_message, data)
|
||||
|
||||
# Clients may disconnect right after [DONE]; a task outlives that cancellation
|
||||
if has_api_outlet_filters and assistant_message and outlet_task is None:
|
||||
line = data.decode('utf-8', 'replace') if isinstance(data, bytes) else data
|
||||
if isinstance(line, str) and any(
|
||||
part.removeprefix('data:').strip() == '[DONE]' for part in line.splitlines()
|
||||
):
|
||||
ctx['assistant_message'] = assistant_message
|
||||
outlet_task = asyncio.create_task(outlet_filter_handler(ctx))
|
||||
|
||||
yield data
|
||||
|
||||
if has_api_outlet_filters and assistant_message:
|
||||
if outlet_task is not None:
|
||||
await asyncio.shield(outlet_task)
|
||||
elif has_api_outlet_filters and assistant_message:
|
||||
ctx['assistant_message'] = assistant_message
|
||||
await outlet_filter_handler(ctx)
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue