fix: handle consecutive same-role messages with string content#2225
Open
fanxing11 wants to merge 1 commit intohuggingface:mainfrom
Open
fix: handle consecutive same-role messages with string content#2225fanxing11 wants to merge 1 commit intohuggingface:mainfrom
fanxing11 wants to merge 1 commit intohuggingface:mainfrom
Conversation
get_clean_message_list crashed with AssertionError when merging consecutive messages of the same role if content was a plain string. The previous assert assumed content is always list-format, but string content is valid (e.g. system messages as dicts with string content). Fix: normalise string content to list format before merging, matching the same format used everywhere else in the function. Fixes huggingface#1972
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1972
What broke
get_clean_message_listraisedAssertionErrorwhen two consecutive messages had the same role and the second one had plain string content:Root cause
When merging consecutive same-role messages, the code assumed
message.contentwas already a list:But
ChatMessage.from_dictnormalises string content to list format only for the first message added tooutput_message_list. A follow-up message with the same role goes through a different path that never did that conversion.Fix
Normalise string content to
[{"type": "text", "text": ..}]before merging, same as the rest of the function already does. Three lines changed, no behaviour change for the existing list-content path.