mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
Fix #19750 : Handle reference images correctly in image edit
- Modified get_last_images() to distinguish between user-uploaded and assistant-generated images - Fixes bug where uploading a reference image after generation would ignore the previously generated image - Assistant images are now prioritized for editing with user references appended
This commit is contained in:
parent
ce945a9334
commit
aa806d12d0
1 changed files with 27 additions and 10 deletions
|
|
@ -716,20 +716,37 @@ async def chat_web_search_handler(
|
||||||
return form_data
|
return form_data
|
||||||
|
|
||||||
|
|
||||||
def get_last_images(message_list):
|
|
||||||
|
|
||||||
|
def get_last_user_images(message_list):
|
||||||
|
"""Get all images from the last USER message only"""
|
||||||
images = []
|
images = []
|
||||||
for message in reversed(message_list):
|
for message in reversed(message_list):
|
||||||
images_flag = False
|
if message.get("role") == "user":
|
||||||
for file in message.get("files", []):
|
for file in message.get("files", []):
|
||||||
if file.get("type") == "image":
|
if file.get("type") == "image":
|
||||||
images.append(file.get("url"))
|
images.append(file.get("url"))
|
||||||
images_flag = True
|
break # Only from most recent user message
|
||||||
|
|
||||||
if images_flag:
|
|
||||||
break
|
|
||||||
|
|
||||||
return images
|
return images
|
||||||
|
|
||||||
|
def get_last_assistant_image(message_list):
|
||||||
|
"""Get the most recent ASSISTANT-generated image"""
|
||||||
|
for message in reversed(message_list):
|
||||||
|
if message.get("role") == "assistant":
|
||||||
|
for file in message.get("files", []):
|
||||||
|
if file.get("type") == "image":
|
||||||
|
return file.get("url")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_last_images(message_list):
|
||||||
|
assistant_image = get_last_assistant_image(message_list)
|
||||||
|
user_images = get_last_user_images(message_list)
|
||||||
|
|
||||||
|
if assistant_image:
|
||||||
|
return [assistant_image] + user_images
|
||||||
|
|
||||||
|
return user_images
|
||||||
|
|
||||||
|
|
||||||
def get_image_urls(delta_images, request, metadata, user) -> list[str]:
|
def get_image_urls(delta_images, request, metadata, user) -> list[str]:
|
||||||
if not isinstance(delta_images, list):
|
if not isinstance(delta_images, list):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue