11
11
{% set ns .system_prompt = ns .system_prompt + '\n\n' + message ['content' ] %}
12
12
{% - endif %}
13
13
{% - endif %}
14
- {% - endfor %}
14
+ {% - endfor - %}
15
15
16
16
{#- Adapted from https://github.com/sgl-project/sglang/blob/main/examples/chat_template/tool_chat_template_deepseekr1.jinja #}
17
17
{% if tools is defined and tools is not none %}
27
27
{% set ns .system_prompt = ns .system_prompt + '\n\n' + tool_ns .text %}
28
28
{% endif %}
29
29
30
- {{ bos_token }}
31
- {{ ns.system_prompt }}
30
+ {{- bos_token }}
31
+ {{- ns.system_prompt }}
32
32
{% - for message in messages %}
33
33
{% set content = message ['content' ] %}
34
34
{% - if message ['role' ] == 'user' %}
45
45
{% - if message ['role' ] == 'assistant' and message ['tool_calls' ] is defined and message ['tool_calls' ] is not none %}
46
46
{% - set ns .is_last_user = false -%}
47
47
{% - if ns .is_tool %}
48
- {{'<|tool▁outputs▁end|>'}}
48
+ {{- '<|tool▁outputs▁end|>'}}
49
49
{% - endif %}
50
50
{% - set ns .is_first = false %}
51
51
{% - set ns .is_tool = false -%}
52
52
{% - set ns .is_output_first = true %}
53
53
{% - for tool in message ['tool_calls' ] %}
54
54
{% - if not ns .is_first %}
55
55
{% - if content is none %}
56
- {{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function'] ['name'] + '\n' + '```json' + '\n' + tool['function'] ['arguments'] |tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
56
+ {{- '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function'] ['name'] + '\n' + '```json' + '\n' + tool['function'] ['arguments'] |tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
57
57
{% - else %}
58
- {{content + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function'] ['name'] + '\n' + '```json' + '\n' + tool['function'] ['arguments'] |tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
58
+ {{- content + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function'] ['name'] + '\n' + '```json' + '\n' + tool['function'] ['arguments'] |tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
59
59
{% - endif %}
60
60
{% - set ns .is_first = true -%}
61
61
{% - else %}
62
- {{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function'] ['name'] + '\n' + '```json' + '\n' + tool['function'] ['arguments'] |tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
62
+ {{- '\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function'] ['name'] + '\n' + '```json' + '\n' + tool['function'] ['arguments'] |tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
63
63
{% - endif %}
64
64
{% - endfor %}
65
- {{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
65
+ {{- '<|tool▁calls▁end|><|end▁of▁sentence|>'}}
66
66
{% - endif %}
67
67
{% - if message ['role' ] == 'assistant' and (message ['tool_calls' ] is not defined or message ['tool_calls' ] is none )%}
68
68
{% - set ns .is_last_user = false -%}
69
69
{% - if ns .is_tool %}
70
- {{'<|tool▁outputs▁end|>' + content + '<|end▁of▁sentence|>'}}
70
+ {{- '<|tool▁outputs▁end|>' + content + '<|end▁of▁sentence|>'}}
71
71
{% - set ns .is_tool = false -%}
72
72
{% - else %}
73
- {{content + '<|end▁of▁sentence|>'}}
73
+ {{- content + '<|end▁of▁sentence|>'}}
74
74
{% - endif %}
75
75
{% - endif %}
76
76
{% - if message ['role' ] == 'tool' %}
77
77
{% - set ns .is_last_user = false -%}
78
78
{% - set ns .is_tool = true -%}
79
79
{% - if ns .is_output_first %}
80
- {{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + content + '<|tool▁output▁end|>'}}
80
+ {{- '<|tool▁outputs▁begin|><|tool▁output▁begin|>' + content + '<|tool▁output▁end|>'}}
81
81
{% - set ns .is_output_first = false %}
82
82
{% - else %}
83
- {{'\n<|tool▁output▁begin|>' + content + '<|tool▁output▁end|>'}}
83
+ {{- '\n<|tool▁output▁begin|>' + content + '<|tool▁output▁end|>'}}
84
84
{% - endif %}
85
85
{% - endif %}
86
86
{% - endfor -%}
87
87
{% if ns .is_tool %}
88
- {{'<|tool▁outputs▁end|>'}}
89
- {% endif %}
88
+ {{- '<|tool▁outputs▁end|>'}}
89
+ {% - endif %}
90
90
{% if add_generation_prompt and not ns .is_last_user and not ns .is_tool %}
91
- {{'<|Assistant|>'}}
92
- {% endif %}
91
+ {{- '<|Assistant|>'}}
92
+ {% - endif %}
0 commit comments