mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
Merge pull request #14362 from PVBLIC-F/fix/chat-engagement-critical
Fix/chat engagement critical
This commit is contained in:
commit
1cb8fa0f03
@ -1001,7 +1001,7 @@ async def process_chat_response(
|
|||||||
message = message_map.get(metadata["message_id"]) if message_map else None
|
message = message_map.get(metadata["message_id"]) if message_map else None
|
||||||
|
|
||||||
if message:
|
if message:
|
||||||
message_list = get_message_list(message_map, message.get("id"))
|
message_list = get_message_list(message_map, metadata["message_id"])
|
||||||
|
|
||||||
# Remove details tags and files from the messages.
|
# Remove details tags and files from the messages.
|
||||||
# as get_message_list creates a new list, it does not affect
|
# as get_message_list creates a new list, it does not affect
|
||||||
@ -1027,7 +1027,7 @@ async def process_chat_response(
|
|||||||
messages.append(
|
messages.append(
|
||||||
{
|
{
|
||||||
**message,
|
**message,
|
||||||
"role": message["role"],
|
"role": message.get("role", "assistant"), # Safe fallback for missing role
|
||||||
"content": content,
|
"content": content,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -1195,6 +1195,7 @@ async def process_chat_response(
|
|||||||
metadata["chat_id"],
|
metadata["chat_id"],
|
||||||
metadata["message_id"],
|
metadata["message_id"],
|
||||||
{
|
{
|
||||||
|
"role": "assistant",
|
||||||
"content": content,
|
"content": content,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -34,11 +34,15 @@ def get_message_list(messages, message_id):
|
|||||||
:return: List of ordered messages starting from the root to the given message
|
:return: List of ordered messages starting from the root to the given message
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Handle case where messages is None
|
||||||
|
if not messages:
|
||||||
|
return [] # Return empty list instead of None to prevent iteration errors
|
||||||
|
|
||||||
# Find the message by its id
|
# Find the message by its id
|
||||||
current_message = messages.get(message_id)
|
current_message = messages.get(message_id)
|
||||||
|
|
||||||
if not current_message:
|
if not current_message:
|
||||||
return None
|
return [] # Return empty list instead of None to prevent iteration errors
|
||||||
|
|
||||||
# Reconstruct the chain by following the parentId links
|
# Reconstruct the chain by following the parentId links
|
||||||
message_list = []
|
message_list = []
|
||||||
@ -47,7 +51,7 @@ def get_message_list(messages, message_id):
|
|||||||
message_list.insert(
|
message_list.insert(
|
||||||
0, current_message
|
0, current_message
|
||||||
) # Insert the message at the beginning of the list
|
) # Insert the message at the beginning of the list
|
||||||
parent_id = current_message["parentId"]
|
parent_id = current_message.get("parentId") # Use .get() for safety
|
||||||
current_message = messages.get(parent_id) if parent_id else None
|
current_message = messages.get(parent_id) if parent_id else None
|
||||||
|
|
||||||
return message_list
|
return message_list
|
||||||
|
Loading…
Reference in New Issue
Block a user