Merge pull request #14362 from PVBLIC-F/fix/chat-engagement-critical

Fix/chat engagement critical
This commit is contained in:
Tim Jaeryang Baek 2025-05-27 02:17:34 +04:00 committed by GitHub
commit 1cb8fa0f03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View File

@ -1001,7 +1001,7 @@ async def process_chat_response(
message = message_map.get(metadata["message_id"]) if message_map else None
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.
# as get_message_list creates a new list, it does not affect
@ -1027,7 +1027,7 @@ async def process_chat_response(
messages.append(
{
**message,
"role": message["role"],
"role": message.get("role", "assistant"), # Safe fallback for missing role
"content": content,
}
)
@ -1195,6 +1195,7 @@ async def process_chat_response(
metadata["chat_id"],
metadata["message_id"],
{
"role": "assistant",
"content": content,
},
)

View File

@ -34,11 +34,15 @@ def get_message_list(messages, message_id):
: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
current_message = messages.get(message_id)
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
message_list = []
@ -47,7 +51,7 @@ def get_message_list(messages, message_id):
message_list.insert(
0, current_message
) # 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
return message_list