Skip to content

Commit 4bab3d3

Browse files
zifeitongDarkLight1337
authored andcommitted
Fix mistral
Signed-off-by: Zifei Tong <zifeitong@gmail.com> Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
1 parent 45cbc49 commit 4bab3d3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

vllm/transformers_utils/tokenizers/mistral.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,16 @@ def apply_chat_template(self,
291291

292292
from mistral_common.protocol.instruct.request import (
293293
ChatCompletionRequest)
294+
295+
# mistral-common requires AssistantMessage content to be string [1].
296+
#
297+
# [1]: https://github.com/mistralai/mistral-common/blob/f4a06998b75ed78bbf5aaf569590b772ea26c9f6/src/mistral_common/protocol/instruct/messages.py#L80
298+
for message in messages:
299+
if message.get("role") == "assistant":
300+
content = message.get("content")
301+
if isinstance(content, list):
302+
content = "\n".join(chunk.get("text") for chunk in content)
303+
message["content"] = content
294304
request = ChatCompletionRequest(messages=messages,
295305
tools=tools) # type: ignore[type-var]
296306
encoded = self.mistral.encode_chat_completion(request)

0 commit comments

Comments
 (0)