char-fork/llama.cpp

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

Piotr Wilkin (ilintar)Autoparser - complete refactoring of parser architecture (#18675)566059a26

char/aliceai-t5-moe
2.4 KiB44 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['content'] is none -%}
15    {%- set ns.is_tool = false -%}
16    {%- for tool in message['tool_calls']-%}
17      {%- if not ns.is_first -%}{{'<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}
18        {%- set ns.is_first = true -%}
19        {%- else -%}{{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
20      {%- endif -%}
21    {%- endfor -%}
22  {%- endif -%}
23  {%- if message['role'] == 'assistant' and message['content'] is not none -%}
24    {%- if ns.is_tool -%}{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}
25      {%- set ns.is_tool = false -%}
26      {%- else -%}
27      {%- set content = message['content'] -%}
28      {%- if '</think>' in content -%}
29        {%- set content = content.split('</think>')[-1] -%}
30      {%- endif -%}{{'<|Assistant|>' + content + '<|end▁of▁sentence|>'}}
31    {%- endif -%}
32  {%- endif -%}
33  {%- if message['role'] == 'tool' -%}
34    {%- set ns.is_tool = true -%}
35    {%- if ns.is_output_first -%}{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}
36      {%- set ns.is_output_first = false -%}
37      {%- else -%}{{'\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}
38    {%- endif -%}
39  {%- endif -%}
40{%- endfor -%}
41{%- if ns.is_tool -%}{{'<|tool▁outputs▁end|>'}}
42{%- endif -%}
43{%- if add_generation_prompt and not ns.is_tool -%}{{'<|Assistant|><think>\n'}}
44{%- endif %}