char-fork/llama.cpp

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

Piotr Wilkin (ilintar)common/parser: add proper reasoning tag prefill reading (#20424)5e54d51b1

char/aliceai-t5-moe
2.5 KiB47 linesraw
1{% if not add_generation_prompt is defined -%}
2  {%- set add_generation_prompt = false -%}
3{%- endif -%}
4{%- set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='') -%}
5{%- for message in messages -%}
6  {%- if message['role'] == 'system' -%}
7    {%- set ns.system_prompt = message['content'] -%}
8  {%- endif -%}
9{%- endfor -%}{{bos_token}}{{ns.system_prompt}}
10{%- for message in messages -%}
11  {%- if message['role'] == 'user' -%}
12    {%- set ns.is_tool = false -%}{{'<|User|>' + message['content']}}
13  {%- endif -%}
14  {%- if message['role'] == 'assistant' and message['tool_calls'] -%}
15    {%- set ns.is_tool = false -%}
16    {%- for tool in message['tool_calls']-%}
17      {%- if not ns.is_first -%}
18        {{'<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] | tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
19        {%- set ns.is_first = true -%}
20      {%- else -%}
21        {{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] | tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
22      {%- endif -%}
23    {%- endfor -%}
24    {{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
25  {%- endif -%}
26  {%- if message['role'] == 'assistant' and message['content'] is not none -%}
27    {%- if ns.is_tool -%}{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}
28      {%- set ns.is_tool = false -%}
29    {%- else -%}
30      {%- set content = message['content'] -%}
31      {%- if '</think>' in content -%}
32        {%- set content = content.split('</think>')[-1] -%}
33      {%- endif -%}{{'<|Assistant|>' + content + '<|end▁of▁sentence|>'}}
34    {%- endif -%}
35  {%- endif -%}
36  {%- if message['role'] == 'tool' -%}
37    {%- set ns.is_tool = true -%}
38    {%- if ns.is_output_first -%}{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}
39      {%- set ns.is_output_first = false -%}
40      {%- else -%}{{'\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}
41    {%- endif -%}
42  {%- endif -%}
43{%- endfor -%}
44{%- if ns.is_tool -%}{{'<|tool▁outputs▁end|>'}}
45{%- endif -%}
46{%- if add_generation_prompt and not ns.is_tool -%}{{'<|Assistant|><think>\n'}}{% if not enable_thinking %}{{- '</think>' -}}{% endif %}
47{%- endif %}