diff --git a/llama_cpp/llama_chat_format.py b/llama_cpp/llama_chat_format.py index f738ab9bb..3236af952 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -3465,33 +3465,53 @@ class Qwen25VLChatHandler(Llava15ChatHandler): DEFAULT_SYSTEM_MESSAGE = "You are a helpful assistant." CHAT_FORMAT = ( - #"{% set image_count = namespace(value=0) %}" - #"{% set video_count = namespace(value=0) %}" - "{% for message in messages %}" - "{% 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'] }}<|im_end|>\n" - "{% else %}" - "{% for content in message['content'] %}" - "{% 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 %}" - "<|im_end|>\n" - "{% endif %}" - "{% endfor %}" - "<|im_start|>assistant\n" + "{%- set image_count = namespace(value=0) -%}" + "{%- for message in messages -%}" + "{%- if loop.first and message[\"role\"] != \"system\" -%}" + "{{- \"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n\" -}}" + "{%- endif -%}" + "{{- \"<|im_start|>\" -}}" + "{{- message[\"role\"] -}}" + "{{- \"\n\" -}}" + "{%- if message[\"content\"] is string -%}" + "{{- message[\"content\"] -}}" + "{{- \"<|im_end|>\n\" -}}" + "{%- else -%}" + "{%- for content in message[\"content\"] -%}" + "{%- if content[\"type\"] == \"image\" or \"image\" in content -%}" + "{%- set image_count.value = image_count.value + 1 -%}" + "{%- if add_vision_id -%}" + "{{- \"Picture \" -}}" + "{{- image_count.value -}}" + "{{- \": \" -}}" + "{%- endif -%}" + "{{- \"<|vision_start|>\" -}}" + "{{- content.image -}}" + "{{- \"<|vision_end|>\" -}}" + "{%- elif content[\"type\"] == \"image_url\" or \"image_url\" in content -%}" + "{%- set image_count.value = image_count.value + 1 -%}" + "{%- if add_vision_id -%}" + "{{- \"Picture \" -}}" + "{{- image_count.value -}}" + "{{- \": \" -}}" + "{%- endif -%}" + "{{- \"<|vision_start|>\" -}}" + "{%- if content.image_url is string -%}" + "{{- content.image_url -}}" + "{%- else -%}" + "{{- content.image_url.url -}}" + "{%- endif -%}" + "{{- \"<|vision_end|>\" -}}" + "{%- elif \"text\" in content -%}" + "{{- content[\"text\"] -}}" + "{%- endif -%}" + "{%- endfor -%}" + "{{- \"<|im_end|>\n\" -}}" + "{%- endif -%}" + "{%- endfor -%}" + "{%- if add_generation_prompt -%}" + "{{- \"<|im_start|>assistant\n\" -}}" + "{%- endif -%}" ) def __call__(self, **kwargs):