Skip to content

Commit c8579d7

Browse files
authored
fix: Better chat format for Qwen2.5-VL (#2040)
1 parent a99fd21 commit c8579d7

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,26 +3459,29 @@ class Qwen25VLChatHandler(Llava15ChatHandler):
34593459
DEFAULT_SYSTEM_MESSAGE = "You are a helpful assistant."
34603460

34613461
CHAT_FORMAT = (
3462-
"<|im_start|>system\n"
3463-
"You are a helpful assistant.<|im_end|>\n"
3462+
#"{% set image_count = namespace(value=0) %}"
3463+
#"{% set video_count = namespace(value=0) %}"
34643464
"{% for message in messages %}"
3465-
"{% if message['role'] == 'user' %}"
3466-
"<|im_start|>user\n"
3465+
"{% if loop.first and message['role'] != 'system' %}"
3466+
"<|im_start|>system\n"
3467+
"{{ self.DEFAULT_SYSTEM_MESSAGE }}<|im_end|>\n"
3468+
"{% endif %}"
3469+
"<|im_start|>{{ message['role'] }}\n"
34673470
"{% if message['content'] is string %}"
3468-
"{{ message['content'] }}"
3471+
"{{ message['content'] }}<|im_end|>\n"
34693472
"{% else %}"
34703473
"{% for content in message['content'] %}"
3471-
"{% if content['type'] == 'text' %}"
3472-
"{{ content['text'] }}"
3473-
"{% elif content['type'] == 'image_url' %}"
3474+
"{% if content['type'] == 'image_url' %}"
34743475
"{% if content.image_url is string %}"
34753476
"{{ content.image_url }}"
34763477
"{% else %}"
34773478
"{{ content.image_url.url }}"
34783479
"{% endif %}"
3480+
#"{% set image_count.value = image_count.value + 1 %}"
3481+
"{% elif content['type'] == 'text' %}"
3482+
"{{ content['text'] }}"
34793483
"{% endif %}"
34803484
"{% endfor %}"
3481-
"{% endif %}"
34823485
"<|im_end|>\n"
34833486
"{% endif %}"
34843487
"{% endfor %}"

0 commit comments

Comments
 (0)