Skip to content

Commit 5a730ae

Browse files
update moonshotai-Kimi-K2.jinja
1 parent 02f4a63 commit 5a730ae

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed
Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
1-
{% if tools -%}
2-
{{ '<|im_system|>tool_declare<|im_middle|>' -}}
3-
{{- tools | tojson -}}
4-
{{ '<|im_end|>' -}}
1+
{%- if tools -%}
2+
<|im_system|>tool_declare<|im_middle|>{{ tools | tojson }}<|im_end|>
53
{%- endif -%}
6-
74
{%- for message in messages -%}
85
{%- if loop.first and messages[0]['role'] != 'system' -%}
9-
{{ '<|im_system|>system<|im_middle|>You are a helpful assistant<|im_end|>' }}
6+
<|im_system|>system<|im_middle|>You are a helpful assistant<|im_end|>
107
{%- endif -%}
118
{%- if message['role'] == 'system' -%}
12-
{{ '<|im_system|>system<|im_middle|>' }}
9+
<|im_system|>system<|im_middle|>
1310
{%- elif message['role'] == 'user' -%}
14-
{{ '<|im_user|>user<|im_middle|>' }}
11+
<|im_user|>user<|im_middle|>
1512
{%- elif message['role'] == 'assistant' -%}
16-
{{ '<|im_assistant|>assistant<|im_middle|>' }}
13+
<|im_assistant|>assistant<|im_middle|>
1714
{%- elif message['role'] == 'tool' -%}
18-
{{ '<|im_system|>tool<|im_middle|>' }}
15+
<|im_system|>tool<|im_middle|>
1916
{%- endif -%}
20-
21-
{%- if message['content'] is string -%}
22-
{{- message['content'] + '<|im_end|>' -}}
23-
{%- else -%}
24-
{%- for content in message['content'] -%}
25-
{%- if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
26-
{{ '<|media_start|>image<|media_content|><|media_pad|><|media_end|>' }}
27-
{%- else -%}
17+
{%- if message['role'] == 'assistant' and message.get('tool_calls') -%}
18+
{%- if message['content'] -%}{{ message['content'] }}{%- endif -%}
19+
<|tool_calls_section_begin|>
20+
{%- for tool_call in message['tool_calls'] -%}
21+
{%- set func_name = tool_call['function']['name'] -%}
22+
{%- set formatted_id = 'functions.' + func_name + ':' + loop.index0|string -%}
23+
<|tool_call_begin|>{{ formatted_id }}<|tool_call_argument_begin|>{{ tool_call['function']['arguments'] | tojson}}<|tool_call_end|>
24+
{%- endfor -%}
25+
<|tool_calls_section_end|>
26+
{%- elif message['role'] == 'tool' -%}
27+
## Return of {{ message.tool_call_id }}\n{{ message['content'] }}
28+
{%- elif message['content'] is string -%}
29+
{{ message['content'] }}
30+
{%- elif message['content'] is not none -%}
31+
{% for content in message['content'] -%}
32+
{% if content['type'] == 'image' or 'image' in content or 'image_url' in content -%}
33+
<|media_start|>image<|media_content|><|media_pad|><|media_end|>
34+
{% else -%}
2835
{{ content['text'] }}
2936
{%- endif -%}
3037
{%- endfor -%}
31-
{{ '<|im_end|>' }}
3238
{%- endif -%}
39+
<|im_end|>
3340
{%- endfor -%}
34-
3541
{%- if add_generation_prompt -%}
36-
{{ '<|im_assistant|>assistant<|im_middle|>' }}
37-
{%- endif -%}
42+
<|im_assistant|>assistant<|im_middle|>
43+
{%- endif -%}

0 commit comments

Comments
 (0)