Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 47 additions & 27 deletions llama_cpp/llama_chat_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading