This commit is contained in:
Yuhong Sun
2025-02-02 16:14:18 -08:00
committed by Evan Lohn
parent a067b32467
commit 506a9f1b94
6 changed files with 149 additions and 125 deletions

View File

@@ -166,6 +166,7 @@ def create_chat_chain(
)
current_message: ChatMessage | None = root_message
previous_message: ChatMessage | None = None
while current_message is not None:
child_msg = current_message.latest_child_message
@@ -183,7 +184,17 @@ def create_chat_chain(
"could not find next message in the same session"
)
mainline_messages.append(current_message)
if (
current_message.message_type == MessageType.ASSISTANT
and previous_message is not None
and previous_message.message_type == MessageType.ASSISTANT
and mainline_messages
):
mainline_messages[-1] = current_message
else:
mainline_messages.append(current_message)
previous_message = current_message
if not mainline_messages:
raise RuntimeError("Could not trace chat message history")