wangzhengtao commited on
Commit
c9d83cc
·
1 Parent(s): 0826e83

add standalone template, allow use name fileld

Browse files
Files changed (2) hide show
  1. chat_template.jinja +50 -0
  2. tokenizer_config.json +1 -1
chat_template.jinja ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ {%- if message['role'] == 'system' -%}
11
+ <|im_system|>system<|im_middle|>
12
+ {%- elif message['role'] == 'user' -%}
13
+ <|im_user|>user<|im_middle|>
14
+ {%- elif message['role'] == 'assistant' -%}
15
+ <|im_assistant|>assistant<|im_middle|>
16
+ {%- elif message['role'] == 'tool' -%}
17
+ <|im_system|>tool<|im_middle|>
18
+ {%- else -%}
19
+ {%- if message.get('name') -%}
20
+ <|im_system|>{{ message['name'] }}<|im_middle|>
21
+ {%- endif -%}
22
+ {%- endif -%}
23
+
24
+ {%- if message['role'] == 'assistant' and message.get('tool_calls') -%}
25
+ {%- if message['content'] -%}{{ message['content'] }}{%- endif -%}
26
+ <|tool_calls_section_begin|>
27
+ {%- for tool_call in message['tool_calls'] -%}
28
+ {%- set formatted_id = tool_call['id'] -%}
29
+ <|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|>
30
+ {%- endfor -%}
31
+ <|tool_calls_section_end|>
32
+ {%- elif message['role'] == 'tool' -%}
33
+ ## Return of {{ message.tool_call_id }}
34
+ {{ message['content'] }}
35
+ {%- elif message['content'] is string -%}
36
+ {{ message['content'] }}
37
+ {%- elif message['content'] is not none -%}
38
+ {% for content in message['content'] -%}
39
+ {% if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
40
+ <|media_start|>image<|media_content|><|media_pad|><|media_end|>
41
+ {% else -%}
42
+ {{ content['text'] }}
43
+ {%- endif -%}
44
+ {%- endfor -%}
45
+ {%- endif -%}
46
+ <|im_end|>
47
+ {%- endfor -%}
48
+ {%- if add_generation_prompt -%}
49
+ <|im_assistant|>assistant<|im_middle|>
50
+ {%- endif -%}
tokenizer_config.json CHANGED
@@ -151,7 +151,7 @@
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
+ "chat_template": "{%- if tools -%}\n <|im_system|>tool_declare<|im_middle|>\n # Tools\n {{ 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 {%- else -%}\n {%- if message.get('name') -%}\n <|im_system|>{{ message['name'] }}<|im_middle|>\n {%- endif -%}\n {%- endif -%}\n\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",