bigmoyan commited on
Commit
b215bf7
·
verified ·
1 Parent(s): 0826e83

standalone chat template (#47)

Browse files

- add standalone template, allow use name fileld (c9d83cc4e06d582b1fdbbcc6b6f2b50607d8de40)
- fix (115cd5f0c7c8cb835f1d031a2532a1ff6e6d50b7)

Files changed (2) hide show
  1. chat_template.jinja +46 -0
  2. tokenizer_config.json +0 -1
chat_template.jinja ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools -%}
2
+ <|im_system|>tool_declare<|im_middle|>
3
+ # Tools
4
+ {{ tools | tojson }}<|im_end|>
5
+ {%- endif -%}
6
+ {%- for message in messages -%}
7
+ {%- if loop.first and messages[0]['role'] != 'system' -%}
8
+ <|im_system|>system<|im_middle|>You are Kimi, an AI assistant created by Moonshot AI.<|im_end|>
9
+ {%- endif -%}
10
+
11
+ {%- set role_name = message.get('name') or message['role'] -%}
12
+ {%- if message['role'] == 'user' -%}
13
+ <|im_user|>{{role_name}}<|im_middle|>
14
+ {%- elif message['role'] == 'assistant' -%}
15
+ <|im_assistant|>{{role_name}}<|im_middle|>
16
+ {%- else -%}
17
+ <|im_system|>{{role_name}}<|im_middle|>
18
+ {% endif %}
19
+
20
+ {%- if message['role'] == 'assistant' and message.get('tool_calls') -%}
21
+ {%- if message['content'] -%}{{ message['content'] }}{%- endif -%}
22
+ <|tool_calls_section_begin|>
23
+ {%- for tool_call in message['tool_calls'] -%}
24
+ {%- set formatted_id = tool_call['id'] -%}
25
+ <|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|>
26
+ {%- endfor -%}
27
+ <|tool_calls_section_end|>
28
+ {%- elif message['role'] == 'tool' -%}
29
+ ## Return of {{ message.tool_call_id }}
30
+ {{ message['content'] }}
31
+ {%- elif message['content'] is string -%}
32
+ {{ message['content'] }}
33
+ {%- elif message['content'] is not none -%}
34
+ {% for content in message['content'] -%}
35
+ {% if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
36
+ <|media_start|>image<|media_content|><|media_pad|><|media_end|>
37
+ {% else -%}
38
+ {{ content['text'] }}
39
+ {%- endif -%}
40
+ {%- endfor -%}
41
+ {%- endif -%}
42
+ <|im_end|>
43
+ {%- endfor -%}
44
+ {%- if add_generation_prompt -%}
45
+ <|im_assistant|>assistant<|im_middle|>
46
+ {%- endif -%}
tokenizer_config.json CHANGED
@@ -151,7 +151,6 @@
151
  "clean_up_tokenization_spaces": false,
152
  "eos_token": "[EOS]",
153
  "extra_special_tokens": {},
154
- "chat_template": "{%- if tools -%}\n <|im_system|>tool_declare<|im_middle|>{{ tools | tojson }}<|im_end|>\n{%- endif -%}\n{%- for message in messages -%}\n {%- if loop.first and messages[0]['role'] != 'system' -%}\n <|im_system|>system<|im_middle|>You are Kimi, an AI assistant created by Moonshot AI.<|im_end|>\n {%- endif -%}\n {%- if message['role'] == 'system' -%}\n <|im_system|>system<|im_middle|>\n {%- elif message['role'] == 'user' -%}\n <|im_user|>user<|im_middle|>\n {%- elif message['role'] == 'assistant' -%}\n <|im_assistant|>assistant<|im_middle|>\n {%- elif message['role'] == 'tool' -%}\n <|im_system|>tool<|im_middle|>\n {%- endif -%}\n {%- if message['role'] == 'assistant' and message.get('tool_calls') -%}\n {%- if message['content'] -%}{{ message['content'] }}{%- endif -%}\n <|tool_calls_section_begin|>\n {%- for tool_call in message['tool_calls'] -%}\n {%- set formatted_id = tool_call['id'] -%}\n <|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{% if tool_call['function']['arguments'] is string %}{{ tool_call['function']['arguments'] }}{% else %}{{ tool_call['function']['arguments'] | tojson }}{% endif %}<|tool_call_end|>\n {%- endfor -%}\n <|tool_calls_section_end|>\n {%- elif message['role'] == 'tool' -%}\n ## Return of {{ message.tool_call_id }}\n {{ message['content'] }}\n {%- elif message['content'] is string -%}\n {{ message['content'] }}\n {%- elif message['content'] is not none -%}\n {% for content in message['content'] -%}\n {% if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}\n <|media_start|>image<|media_content|><|media_pad|><|media_end|>\n {% else -%}\n {{ content['text'] }}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n <|im_end|>\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n <|im_assistant|>assistant<|im_middle|>\n{%- endif -%}",
155
  "model_max_length": 1000000000000000019884624838656,
156
  "pad_token": "[PAD]",
157
  "tokenizer_class": "TikTokenTokenizer",
 
151
  "clean_up_tokenization_spaces": false,
152
  "eos_token": "[EOS]",
153
  "extra_special_tokens": {},
 
154
  "model_max_length": 1000000000000000019884624838656,
155
  "pad_token": "[PAD]",
156
  "tokenizer_class": "TikTokenTokenizer",