LucaMotz commited on
Commit
0595932
·
verified ·
1 Parent(s): e56c89f

Chat template as a processor-only chat_template.json

Browse files

The tokenizer also loads a repo-level `chat_template.jinja`, so it replaced the tokenizer's own chat template. `chat_template.json` is read by the processor only, and the tokenizer keeps its template.

Files changed (2) hide show
  1. chat_template.jinja +0 -5
  2. chat_template.json +3 -0
chat_template.jinja DELETED
@@ -1,5 +0,0 @@
1
- {%- macro render_content(content, ns) -%}{%- if content is string -%}{{- content -}}{%- else -%}{%- set parts = namespace(items=[]) -%}{%- for item in content -%}{%- if item['type'] == 'image' -%}{%- set parts.items = parts.items + ['<image_id>' ~ ns.image_count ~ '</image_id><unk>'] -%}{%- set ns.image_count = ns.image_count + 1 -%}{%- elif item['type'] == 'text' -%}{%- set parts.items = parts.items + [item['text']] -%}{%- endif -%}{%- endfor -%}{{- parts.items | join('
2
- ') -}}{%- endif -%}{%- endmacro -%}{%- set images = namespace(image_count=0) -%}{%- for message in messages -%}{{- '<|im_start|>' + message['role'] + '
3
- ' + render_content(message['content'], images) + '<|im_end|>
4
- ' -}}{%- endfor -%}{%- if add_generation_prompt -%}{{- '<|im_start|>assistant
5
- ' -}}{%- endif -%}
 
 
 
 
 
 
chat_template.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "chat_template": "{%- macro render_content(content, ns) -%}{%- if content is string -%}{{- content -}}{%- else -%}{%- set parts = namespace(items=[]) -%}{%- for item in content -%}{%- if item['type'] == 'image' -%}{%- set parts.items = parts.items + ['<image_id>' ~ ns.image_count ~ '</image_id><unk>'] -%}{%- set ns.image_count = ns.image_count + 1 -%}{%- elif item['type'] == 'text' -%}{%- set parts.items = parts.items + [item['text']] -%}{%- endif -%}{%- endfor -%}{{- parts.items | join('\n') -}}{%- endif -%}{%- endmacro -%}{%- set images = namespace(image_count=0) -%}{%- for message in messages -%}{{- '<|im_start|>' + message['role'] + '\n' + render_content(message['content'], images) + '<|im_end|>\n' -}}{%- endfor -%}{%- if add_generation_prompt -%}{{- '<|im_start|>assistant\n' -}}{%- endif -%}"
3
+ }