Repository navigation
Conversation
… formats The built-in chat formatters only read string message content. A user message whose content is a list of text parts (the OpenAI content-part form, which llama_types allows) was dropped from the prompt, and the mistral-instruct formatter raised TypeError on an assistant message with list content. Join the text parts of list content in _map_roles, _get_system_message and format_mistral_instruct. Add test_chat_formatters_keep_text_of_content_parts.
sohailshk
force-pushed
the
fix/list-content-parts
branch
from
November 25, 2026 03:18
f8aaf50 to
c4a49d9
Compare
This branch has not been deployed
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.
The built-in chat formatters drop the text of a message whose content is a list of text parts, which is the OpenAI content-part form that
llama_typesallows for user messages.Related: #1080
Repro:
register_chat_format. List-typed assistant content is dropped in 22 of them;format_mistral_instructraisesTypeErroron it instead.llama-2,qwen,oasst_llama,baichuan-2,baichuan,mistrallite,zephyr,pygmalion,chatml,chatglm3,openchat) insert it as a Python list repr ([{'type': 'text', 'text': ...}]), andalpaca,redpajama-inciteandsnoozyraiseTypeError.Fix:
_map_roles,_get_system_messageandformat_mistral_instructread the text of a list content through a small_content_texthelper. The text parts are joined with"", and non-text parts (for exampleimage_url) are ignored. Content with no text parts (for example image-only content) contributes no text.Test:
test_chat_formatters_keep_text_of_content_partschecks that six formatters give the same prompt for list content (one user message also has animage_urlpart) and for string content.Red/green: on main, 6 of the 8 tests in
tests/test_llama_chat_format.pyfail (the six new parametrized cases; 2 pass). With this change all 8 pass. A sweep over all 23 registered formats shows that list content gives the same prompt as string content, and that string,Noneand empty content prompts are unchanged from main (184 cases).ruff checkandruff format --checkpass on the touched files. Changelog entry added under Unreleased.Not run: tests that need a GGUF model, and the server tests.
The implementation and tests were written with AI assistance.