char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Guido Imperialechat : Align Laguna-S-2.1 chat template to huggingface (#26232)a52077c4c

char/aliceai-t5-moe
3.9 KiB94 linesraw
1{#- Iteration on laguna_glm_thinking_v8/chat_template.jinja -#}
2{#- No formatting instructions -#}
3{{- "〈|EOS|〉" -}}
4{%- set enable_thinking = enable_thinking | default(true) -%}
5{%- set add_generation_prompt = add_generation_prompt | default(false) -%}
6{%- set preserve_thinking = preserve_thinking | default(false) -%}
7
8{#- ───── header (system message) ───── -#}
9{#- A caller-supplied system message with empty content opts out of the default below, producing no <system> block — used to train without a system message. -#}
10{%- set system_message = "You are a helpful, conversationally-fluent assistant made by Poolside. You are here to be helpful to users through natural language conversations." -%}
11{%- if messages and messages[0].role == "system" -%}
12  {%- set system_message = messages[0].content -%}
13  {%- set messages = messages[1:] -%}
14{%- endif -%}
15
16{%- set has_sys = system_message and system_message.strip() -%}
17{%- if has_sys or tools or enable_thinking -%}
18  {{- "<system>" -}}
19
20  {%- if has_sys -%}
21    {{- system_message.rstrip() -}}
22    {%- if tools -%}{{- "\n\n" -}}{%- endif -%}
23  {%- endif -%}
24
25  {%- if tools -%}
26    {{- "### Tools\n\n" -}}
27    {{- "You may call functions to assist with the user query.\n" -}}
28    {{- "All available function signatures are listed below:\n" -}}
29    {{- "<available_tools>\n" -}}
30    {%- for tool in tools -%}
31      {{- (tool | tojson) ~ "\n" -}}
32    {%- endfor -%}
33    {{- "</available_tools>" -}}
34  {%- endif -%}
35
36  {{- "</system>\n" -}}
37{%- endif -%}
38
39{#- ───── main loop ───── -#}
40{%- for message in messages -%}
41  {%- set content = message.content if message.content is string else "" -%}
42  {%- if message.role == "user" -%}
43    {{- "<user>" + content + "</user>\n" -}}
44  {%- elif message.role == "assistant" -%}
45    {%- generation -%}
46      {{- "<assistant>" -}}
47      {#- Extract reasoning content from message.reasoning (vLLM field name) or message.reasoning_content -#}
48      {%- set reasoning_content = '' -%}
49      {%- if message.reasoning is string -%}
50        {%- set reasoning_content = message.reasoning -%}
51      {%- elif message.reasoning_content is string -%}
52        {%- set reasoning_content = message.reasoning_content -%}
53      {%- endif -%}
54      {#- Display reasoning content for all messages if enable_thinking -#}
55      {%- if enable_thinking or preserve_thinking -%}
56        {{- '<think>' + reasoning_content + '</think>' -}}
57      {%- else -%}
58        {{- '</think>' -}}
59      {%- endif -%}
60      {#- Display main content (trailing newline only when no tool_calls follow) -#}
61      {%- if content -%}
62        {{- content -}}
63      {%- endif -%}
64      {%- if message.tool_calls -%}
65        {%- for tool_call in message.tool_calls -%}
66          {%- set function_data = tool_call.function -%}
67          {{- '<tool_call>' + function_data.name -}}
68          {%- set _args = function_data.arguments -%}
69          {%- for k, v in _args.items() -%}
70            {{- "<arg_key>" ~ k ~ "</arg_key>" -}}
71            {{- "<arg_value>" -}}{{- v | tojson(ensure_ascii=False) if v is not string else v -}}{{- "</arg_value>" -}}
72          {%- endfor -%}
73          {{- "</tool_call>" -}}
74        {%- endfor -%}
75      {%- endif -%}
76      {{- "</assistant>\n" -}}
77    {%- endgeneration -%}
78  {%- elif message.role == "tool" -%}
79    {{- "<tool_response>" + content + "</tool_response>\n" -}}
80  {%- elif message.role == "system" -%}
81    {#- Render additional system messages (the first one, if any, is handled separately in the header and was sliced off above) -#}
82    {{- "<system>" + content + "</system>\n" -}}
83  {%- endif -%}
84{%- endfor -%}
85{#- ───── generation prompt ───── -#}
86{%- if add_generation_prompt -%}
87  {{- "<assistant>" -}}
88  {#- ───── Include reasoning mode directive ───── -#}
89  {%- if enable_thinking -%}
90    {{- '<think>' -}}
91  {%- else -%}
92    {{- '</think>' -}}
93  {%- endif -%}
94{%- endif -%}