[bugfix] do not add extra linebreak for score/rerank with chat template (#38617)

Signed-off-by: augusto.yjh <augusto.yjh@antgroup.com>
Signed-off-by: wang.yuqi <noooop@126.com>
Co-authored-by: wang.yuqi <yuqi.wang@daocloud.io>
Co-authored-by: wang.yuqi <noooop@126.com>
Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
This commit is contained in:
Augusto Yao
2026-04-01 04:50:07 +00:00
committed by GitHub
co-authored by wang.yuqi wang.yuqi Cyrus Leung
parent eb47454987
commit ef53395e2c
3 changed files with 14 additions and 6 deletions
+10 -3
View File
@@ -1187,6 +1187,7 @@ def _get_full_multimodal_text_prompt(
placeholder_storage: dict[str, list],
texts: list[str],
interleave_strings: bool,
multimodal_content_part_separator: str = "\n",
) -> str:
"""Combine multimodal prompts for a multimodal language model."""
@@ -1232,9 +1233,11 @@ def _get_full_multimodal_text_prompt(
# NOTE: Default behaviour: we always add missing placeholders
# at the front of the prompt, if interleave_strings=False
if text_prompt:
return "\n".join(missing_placeholders + [text_prompt])
return multimodal_content_part_separator.join(
missing_placeholders + [text_prompt]
)
else:
return "\n".join(missing_placeholders)
return multimodal_content_part_separator.join(missing_placeholders)
# No need to validate using Pydantic again
@@ -1384,6 +1387,7 @@ def _parse_chat_message_content_parts(
wrap_dicts: bool,
interleave_strings: bool,
mm_processor_kwargs: dict[str, Any] | None = None,
multimodal_content_part_separator="\n",
) -> list[ConversationMessage]:
content = list[_ContentPart]()
@@ -1406,7 +1410,10 @@ def _parse_chat_message_content_parts(
mm_placeholder_storage = mm_parser.mm_placeholder_storage()
if mm_placeholder_storage:
text_prompt = _get_full_multimodal_text_prompt(
mm_placeholder_storage, texts, interleave_strings
mm_placeholder_storage,
texts,
interleave_strings,
multimodal_content_part_separator=multimodal_content_part_separator,
)
else:
text_prompt = "\n".join(texts)