Support OpenAI-compatible multimodal content part aliases in chat template

#109
Files changed (1) hide show
  1. chat_template.jinja +9 -7
chat_template.jinja CHANGED
@@ -296,11 +296,12 @@
296
  {%- endfor -%}
297
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
298
  {%- for part in tool_body -%}
299
- {%- if part.get('type') == 'image' -%}
 
300
  {{- '<|image|>' -}}
301
- {%- elif part.get('type') == 'audio' -%}
302
  {{- '<|audio|>' -}}
303
- {%- elif part.get('type') == 'video' -%}
304
  {{- '<|video|>' -}}
305
  {%- endif -%}
306
  {%- endfor -%}
@@ -322,19 +323,20 @@
322
  {%- endif -%}
323
  {%- elif message['content'] is sequence -%}
324
  {%- for item in message['content'] -%}
325
- {%- if item['type'] == 'text' -%}
 
326
  {%- if role == 'model' -%}
327
  {{- strip_thinking(item['text']) -}}
328
  {%- else -%}
329
  {{- item['text'] | trim -}}
330
  {%- endif -%}
331
- {%- elif item['type'] == 'image' -%}
332
  {{- '<|image|>' -}}
333
  {%- set ns.prev_message_type = 'image' -%}
334
- {%- elif item['type'] == 'audio' -%}
335
  {{- '<|audio|>' -}}
336
  {%- set ns.prev_message_type = 'audio' -%}
337
- {%- elif item['type'] == 'video' -%}
338
  {{- '<|video|>' -}}
339
  {%- set ns.prev_message_type = 'video' -%}
340
  {%- endif -%}
 
296
  {%- endfor -%}
297
  {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}
298
  {%- for part in tool_body -%}
299
+ {%- set part_type = part.get('type') -%}
300
+ {%- if part_type in ['image', 'image_url'] -%}
301
  {{- '<|image|>' -}}
302
+ {%- elif part_type in ['audio', 'audio_url', 'input_audio'] -%}
303
  {{- '<|audio|>' -}}
304
+ {%- elif part_type in ['video', 'video_url'] -%}
305
  {{- '<|video|>' -}}
306
  {%- endif -%}
307
  {%- endfor -%}
 
323
  {%- endif -%}
324
  {%- elif message['content'] is sequence -%}
325
  {%- for item in message['content'] -%}
326
+ {%- set item_type = item.get('type') -%}
327
+ {%- if item_type == 'text' -%}
328
  {%- if role == 'model' -%}
329
  {{- strip_thinking(item['text']) -}}
330
  {%- else -%}
331
  {{- item['text'] | trim -}}
332
  {%- endif -%}
333
+ {%- elif item_type in ['image', 'image_url'] -%}
334
  {{- '<|image|>' -}}
335
  {%- set ns.prev_message_type = 'image' -%}
336
+ {%- elif item_type in ['audio', 'audio_url', 'input_audio'] -%}
337
  {{- '<|audio|>' -}}
338
  {%- set ns.prev_message_type = 'audio' -%}
339
+ {%- elif item_type in ['video', 'video_url'] -%}
340
  {{- '<|video|>' -}}
341
  {%- set ns.prev_message_type = 'video' -%}
342
  {%- endif -%}