refac
This commit is contained in:
@@ -4145,12 +4145,14 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
if delta_count >= delta_chunk_size:
|
||||
await flush_pending_delta_data(delta_chunk_size)
|
||||
|
||||
filter_extra_params = {'__body__': form_data, **extra_params} if filter_functions else None
|
||||
|
||||
async for line in response.body_iterator:
|
||||
line = line.decode('utf-8', 'replace') if isinstance(line, bytes) else line
|
||||
data = line
|
||||
|
||||
# Skip empty lines
|
||||
if not data.strip():
|
||||
if not data or data.isspace():
|
||||
continue
|
||||
|
||||
# "data:" is the prefix for each event
|
||||
@@ -4178,20 +4180,21 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
pass
|
||||
continue
|
||||
|
||||
# Remove the prefix
|
||||
data = data[len('data:') :].strip()
|
||||
# Remove the "data:" prefix
|
||||
data = data[5:].strip()
|
||||
|
||||
try:
|
||||
data = json.loads(data)
|
||||
|
||||
data, _ = await process_filter_functions(
|
||||
request=request,
|
||||
filter_context=filter_context,
|
||||
filter_functions=filter_functions,
|
||||
filter_type='stream',
|
||||
form_data=data,
|
||||
extra_params={'__body__': form_data, **extra_params},
|
||||
)
|
||||
if filter_functions:
|
||||
data, _ = await process_filter_functions(
|
||||
request=request,
|
||||
filter_context=filter_context,
|
||||
filter_functions=filter_functions,
|
||||
filter_type='stream',
|
||||
form_data=data,
|
||||
extra_params=filter_extra_params,
|
||||
)
|
||||
|
||||
if data:
|
||||
if 'event' in data and not getattr(request.state, 'direct', False):
|
||||
@@ -4433,7 +4436,12 @@ async def streaming_chat_response_handler(response, ctx):
|
||||
}
|
||||
delta_type = 'tool_call'
|
||||
|
||||
image_urls = await get_image_urls(delta.get('images', []), request, metadata, user)
|
||||
delta_images = delta.get('images')
|
||||
image_urls = (
|
||||
await get_image_urls(delta_images, request, metadata, user)
|
||||
if delta_images
|
||||
else []
|
||||
)
|
||||
if image_urls:
|
||||
image_file_list = [{'type': 'image', 'url': url} for url in image_urls]
|
||||
message_files = image_file_list
|
||||
|
||||
Reference in New Issue
Block a user