Skip to content

Commit f0c9633

Browse files
committed
Better Llava1.5 Chat Format
1 parent 9a004bd commit f0c9633

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

llama_cpp/llama_chat_format.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,36 +2796,35 @@ class Llava15ChatHandler:
27962796

27972797
CHAT_FORMAT = (
27982798
"{% for message in messages %}"
2799-
"{% if message.role == 'system' %}"
2800-
"{{ message.content }}"
2801-
"{% endif %}"
2802-
"{% if message.role == 'user' %}"
2803-
"{% if message.content is string %}"
2804-
"\nUSER: {{ message.content }}"
2805-
"{% endif %}"
2806-
"{% if message.content is iterable %}"
2807-
"\nUSER: "
2808-
"{% for content in message.content %}"
2809-
"{% if content.type == 'image_url' and content.image_url is string %}"
2810-
"{{ content.image_url }}"
2811-
"{% endif %}"
2812-
"{% if content.type == 'image_url' and content.image_url is mapping %}"
2813-
"{{ content.image_url.url }}"
2814-
"{% endif %}"
2815-
"{% endfor %}"
2816-
"{% for content in message.content %}"
2817-
"{% if content.type == 'text' %}"
2818-
"{{ content.text }}"
2819-
"{% endif %}"
2820-
"{% endfor %}"
2821-
"{% endif %}"
2822-
"{% endif %}"
2823-
"{% if message.role == 'assistant' and message.content is not none %}"
2824-
"\nASSISTANT: {{ message.content }}"
2825-
"{% endif %}"
2799+
"{% if message.role == 'system' %}"
2800+
"{{ message.content }}"
2801+
"{% endif %}"
2802+
2803+
"{% if message.role == 'user' %}"
2804+
"{% if message.content is string %}"
2805+
"\nUSER: {{ message.content }}"
2806+
"{% elif message.content is iterable %}"
2807+
"\nUSER: "
2808+
"{% for content in message.content %}"
2809+
"{% if content.type == 'image_url' %}"
2810+
"{{ content.image_url if content.image_url is string else content.image_url.url }}"
2811+
"{% endif %}"
2812+
"{% endfor %}"
2813+
"{% for content in message.content %}"
2814+
"{% if content.type == 'text' %}"
2815+
"{{ content.text }}"
2816+
"{% endif %}"
2817+
"{% endfor %}"
2818+
"{% endif %}"
2819+
"{% endif %}"
2820+
2821+
"{% if message.role == 'assistant' and message.content is not none %}"
2822+
"\nASSISTANT: {{ message.content }}"
2823+
"{% endif %}"
28262824
"{% endfor %}"
2825+
28272826
"{% if add_generation_prompt %}"
2828-
"\nASSISTANT: "
2827+
"\nASSISTANT: "
28292828
"{% endif %}"
28302829
)
28312830

0 commit comments

Comments
 (0)