fix: Ensure image renders before text in chat formats regardless of message content order.
This commit is contained in:
parent
d03f15bb73
commit
3489ef09d3
1 changed files with 41 additions and 13 deletions
|
@ -2175,12 +2175,11 @@ class Llava15ChatHandler:
|
||||||
"{% if message.role == 'user' %}"
|
"{% if message.role == 'user' %}"
|
||||||
"{% if message.content is string %}"
|
"{% if message.content is string %}"
|
||||||
"\nUSER: {{ message.content }}"
|
"\nUSER: {{ message.content }}"
|
||||||
"{% elif message.content is iterable %}"
|
|
||||||
"\nUSER: "
|
|
||||||
"{% for content in message.content %}"
|
|
||||||
"{% if content.type == 'text' %}"
|
|
||||||
"{{ content.text }}"
|
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
|
"{% if message.content is iterable %}"
|
||||||
|
"\nUSER: "
|
||||||
|
|
||||||
|
"{% for content in message.content %}"
|
||||||
"{% if content.type == 'image_url' and content.image_url is string %}"
|
"{% if content.type == 'image_url' and content.image_url is string %}"
|
||||||
"{{ content.image_url }}"
|
"{{ content.image_url }}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
|
@ -2188,6 +2187,13 @@ class Llava15ChatHandler:
|
||||||
"{{ content.image_url.url }}"
|
"{{ content.image_url.url }}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% endfor %}"
|
"{% endfor %}"
|
||||||
|
|
||||||
|
"{% for content in message.content %}"
|
||||||
|
"{% if content.type == 'text' %}"
|
||||||
|
"{{ content.text }}"
|
||||||
|
"{% endif %}"
|
||||||
|
"{% endfor %}"
|
||||||
|
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% if message.role == 'assistant' and message.content is not none %}"
|
"{% if message.role == 'assistant' and message.content is not none %}"
|
||||||
|
@ -2575,14 +2581,22 @@ class ObsidianChatHandler(Llava15ChatHandler):
|
||||||
"{{ message.content }}"
|
"{{ message.content }}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% if message.content is iterable %}"
|
"{% if message.content is iterable %}"
|
||||||
|
|
||||||
|
"{% for content in message.content %}"
|
||||||
|
"{% if content.type == 'image_url' and content.image_url is string %}"
|
||||||
|
"{{ content.image_url }}"
|
||||||
|
"{% endif %}"
|
||||||
|
"{% if content.type == 'image_url' and content.image_url is mapping %}"
|
||||||
|
"{{ content.image_url.url }}"
|
||||||
|
"{% endif %}"
|
||||||
|
"{% endfor %}"
|
||||||
|
|
||||||
"{% for content in message.content %}"
|
"{% for content in message.content %}"
|
||||||
"{% if content.type == 'text' %}"
|
"{% if content.type == 'text' %}"
|
||||||
"{{ content.text }}"
|
"{{ content.text }}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% if content.type == 'image_url' %}"
|
|
||||||
"{{ content.image_url }}"
|
|
||||||
"{% endif %}"
|
|
||||||
"{% endfor %}"
|
"{% endfor %}"
|
||||||
|
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"###\n"
|
"###\n"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
|
@ -2606,9 +2620,9 @@ class MoondreamChatHandler(Llava15ChatHandler):
|
||||||
"{% for message in messages %}"
|
"{% for message in messages %}"
|
||||||
"{% if message.role == 'user' %}"
|
"{% if message.role == 'user' %}"
|
||||||
"{% if message.content is iterable %}"
|
"{% if message.content is iterable %}"
|
||||||
"{% for content in message.content %}"
|
|
||||||
|
|
||||||
# <image>
|
# <image>
|
||||||
|
"{% for content in message.content %}"
|
||||||
"{% if content.type == 'image_url' %}"
|
"{% if content.type == 'image_url' %}"
|
||||||
"{% if content.image_url is string %}"
|
"{% if content.image_url is string %}"
|
||||||
"{{ content.image_url }}\n\n"
|
"{{ content.image_url }}\n\n"
|
||||||
|
@ -2617,12 +2631,15 @@ class MoondreamChatHandler(Llava15ChatHandler):
|
||||||
"{{ content.image_url.url }}\n\n"
|
"{{ content.image_url.url }}\n\n"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
|
"{% endfor %}"
|
||||||
|
|
||||||
# Question:
|
# Question:
|
||||||
|
"{% for content in message.content %}"
|
||||||
"{% if content.type == 'text' %}"
|
"{% if content.type == 'text' %}"
|
||||||
"Question: {{ content.text }}\n\n"
|
"Question: {{ content.text }}\n\n"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% endfor %}"
|
"{% endfor %}"
|
||||||
|
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
|
|
||||||
# Question:
|
# Question:
|
||||||
|
@ -2657,9 +2674,9 @@ class Llava16ChatHandler(Llava15ChatHandler):
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% if message.role == 'user' %}"
|
"{% if message.role == 'user' %}"
|
||||||
"{% if message.content is iterable %}"
|
"{% if message.content is iterable %}"
|
||||||
"{% for content in message.content %}"
|
|
||||||
|
|
||||||
# <image>
|
# <image>
|
||||||
|
"{% for content in message.content %}"
|
||||||
"{% if content.type == 'image_url' %}"
|
"{% if content.type == 'image_url' %}"
|
||||||
"{% if content.image_url is string %}"
|
"{% if content.image_url is string %}"
|
||||||
"{{ content.image_url }}\n"
|
"{{ content.image_url }}\n"
|
||||||
|
@ -2668,12 +2685,15 @@ class Llava16ChatHandler(Llava15ChatHandler):
|
||||||
"{{ content.image_url.url }}\n"
|
"{{ content.image_url.url }}\n"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
|
"{% endfor %}"
|
||||||
|
|
||||||
# Question:
|
# Question:
|
||||||
|
"{% for content in message.content %}"
|
||||||
"{% if content.type == 'text' %}"
|
"{% if content.type == 'text' %}"
|
||||||
"{{ content.text }}"
|
"{{ content.text }}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% endfor %}"
|
"{% endfor %}"
|
||||||
|
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
|
|
||||||
# Question:
|
# Question:
|
||||||
|
@ -2719,14 +2739,22 @@ class NanoLlavaChatHandler(Llava15ChatHandler):
|
||||||
"{{ message.content }}"
|
"{{ message.content }}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% if message.content is iterable %}"
|
"{% if message.content is iterable %}"
|
||||||
|
|
||||||
|
"{% for content in message.content %}"
|
||||||
|
"{% if content.type == 'image_url' and content.image_url is string %}"
|
||||||
|
"{{ content.image_url }}"
|
||||||
|
"{% endif %}"
|
||||||
|
"{% if content.type == 'image_url' and content.image_url is mapping %}"
|
||||||
|
"{{ content.image_url.url }}"
|
||||||
|
"{% endif %}"
|
||||||
|
"{% endfor %}"
|
||||||
|
|
||||||
"{% for content in message.content %}"
|
"{% for content in message.content %}"
|
||||||
"{% if content.type == 'text' %}"
|
"{% if content.type == 'text' %}"
|
||||||
"{{ content.text }}"
|
"{{ content.text }}"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"{% if content.type == 'image_url' %}"
|
|
||||||
"{{ content.image_url }}"
|
|
||||||
"{% endif %}"
|
|
||||||
"{% endfor %}"
|
"{% endfor %}"
|
||||||
|
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
"<|im_end|>"
|
"<|im_end|>"
|
||||||
"{% endif %}"
|
"{% endif %}"
|
||||||
|
|
Loading…
Reference in a new issue