thehekimoghlu commited on
Commit
0e4c85c
·
verified ·
1 Parent(s): 84c0b3f

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +52 -0
chat_template.jinja ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% macro render_content(msg) -%}
2
+ {%- set c = msg.get('content') -%}
3
+ {%- if c is string -%}
4
+ {{ c }}
5
+ {%- elif c is not none -%}
6
+ {% for content in c -%}
7
+ {% if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
8
+ <|media_start|>image<|media_content|><|media_pad|><|media_end|>
9
+ {% else -%}
10
+ {{ content['text'] }}
11
+ {%- endif -%}
12
+ {%- endfor -%}
13
+ {%- endif -%}
14
+ {%- endmacro %}
15
+
16
+
17
+ {%- if tools -%}
18
+ <|im_system|>tool_declare<|im_middle|>{{ tools | tojson(separators=(',', ':')) }}<|im_end|>
19
+ {%- endif -%}
20
+ {% for message in messages %}
21
+ {%- if loop.first and messages[0]['role'] != 'system' -%}
22
+ <|im_system|>system<|im_middle|>You are Kimi, an AI assistant created by Moonshot AI.<|im_end|>
23
+ {% endif %}
24
+
25
+ {%- set role_name = message.get('name') or message['role'] -%}
26
+ {%- if message['role'] == 'user' -%}
27
+ <|im_user|>{{role_name}}<|im_middle|>
28
+ {%- elif message['role'] == 'assistant' -%}
29
+ <|im_assistant|>{{role_name}}<|im_middle|>
30
+ {%- else -%}
31
+ <|im_system|>{{role_name}}<|im_middle|>
32
+ {%- endif -%}
33
+
34
+ {%- if message['role'] == 'assistant' and message.get('tool_calls') -%}
35
+ {{render_content(message)}}<|tool_calls_section_begin|>
36
+ {%- for tool_call in message['tool_calls'] -%}
37
+ {%- set formatted_id = tool_call['id'] -%}
38
+ <|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|>
39
+ {%- endfor -%}
40
+ <|tool_calls_section_end|>
41
+ {%- elif message['role'] == 'tool' -%}
42
+ {%- set tool_call_id = message.tool_call_id -%}
43
+ ## Return of {{ tool_call_id }}
44
+ {{render_content(message)}}
45
+ {%- elif message['content'] is not none -%}
46
+ {{render_content(message)}}
47
+ {%- endif -%}
48
+ <|im_end|>
49
+ {%- endfor -%}
50
+ {%- if add_generation_prompt -%}
51
+ <|im_assistant|>assistant<|im_middle|>
52
+ {%- endif -%}