From 61a1567f7d654980e52d5261a71377e71f267fcd Mon Sep 17 00:00:00 2001 From: AlcoftTAO Date: Wed, 9 Jul 2025 01:44:56 +0200 Subject: [PATCH] Better chat format for Qwen2.5-VL --- llama_cpp/llama_chat_format.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/llama_cpp/llama_chat_format.py b/llama_cpp/llama_chat_format.py index a288db7b0..2a7d575ce 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -3459,26 +3459,29 @@ class Qwen25VLChatHandler(Llava15ChatHandler): DEFAULT_SYSTEM_MESSAGE = "You are a helpful assistant." CHAT_FORMAT = ( - "<|im_start|>system\n" - "You are a helpful assistant.<|im_end|>\n" + #"{% set image_count = namespace(value=0) %}" + #"{% set video_count = namespace(value=0) %}" "{% for message in messages %}" - "{% if message['role'] == 'user' %}" - "<|im_start|>user\n" + "{% if loop.first and message['role'] != 'system' %}" + "<|im_start|>system\n" + "{{ self.DEFAULT_SYSTEM_MESSAGE }}<|im_end|>\n" + "{% endif %}" + "<|im_start|>{{ message['role'] }}\n" "{% if message['content'] is string %}" - "{{ message['content'] }}" + "{{ message['content'] }}<|im_end|>\n" "{% else %}" "{% for content in message['content'] %}" - "{% if content['type'] == 'text' %}" - "{{ content['text'] }}" - "{% elif content['type'] == 'image_url' %}" + "{% if content['type'] == 'image_url' %}" "{% if content.image_url is string %}" "{{ content.image_url }}" "{% else %}" "{{ content.image_url.url }}" "{% endif %}" + #"{% set image_count.value = image_count.value + 1 %}" + "{% elif content['type'] == 'text' %}" + "{{ content['text'] }}" "{% endif %}" "{% endfor %}" - "{% endif %}" "<|im_end|>\n" "{% endif %}" "{% endfor %}"