char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
1c0d9081f
char/aliceai-t5-moe
1{%- if not add_generation_prompt is defined -%} 2{%- set add_generation_prompt = false -%} 3{%- endif -%} 4{%- if not thinking is defined -%} 5{%- if enable_thinking is defined -%} 6{%- set thinking = enable_thinking -%} 7{%- else -%} 8{%- set thinking = false -%} 9{%- endif -%} 10{%- endif -%} 11{%- set dsml_token = '|DSML|' -%} 12{%- set thinking_start_token = '<think>' -%} 13{%- set thinking_end_token = '</think>' -%} 14{%- set tools_header = '## Tools\n\nYou have access to a set of tools you can use to answer the user\' s question .\ nYou can invoke functions by writing a "<' + dsml_token + 'function_calls>" block like the following as part of your reply to the user :\ n < ' + dsml_token + ' function_calls >\ n < ' + dsml_token + ' invoke name = "$FUNCTION_NAME" >\ n < ' + dsml_token + ' parameter name = "$PARAMETER_NAME" string = "true|false" >$ PARAMETER_VALUE </ ' + dsml_token + ' parameter >\ n ...\ n </ ' + dsml_token + ' invoke >\ n < ' + dsml_token + ' invoke name = "$FUNCTION_NAME2" >\ n ...\ n </ ' + dsml_token + ' invoke >\ n </ ' + dsml_token + ' function_calls >\ n \ nString and scalar parameters should be specified as is without any escaping or quotes , while lists and objects should use JSON format . The "string" attribute should be set to "true" for string type parameters and "false" for other types ( numbers , booleans , arrays , objects ).\ n \ nIf the thinking_mode is enabled , then after function results you should strongly consider outputting a thinking block . Here is an example :\ n \ n < ' + dsml_token + ' function_calls >\ n ...\ n </ ' + dsml_token + ' function_calls >\ n \ n < function_results >\ n ...\ n </ function_results >\ n \ n ' + thinking_start_token + ' ... thinking about results ' + thinking_end_token + ' \ n \ nHere are the functions available in JSONSchema format :\ n < functions >\ n ' -%} 15{%- set tools_footer = ' </ functions >\ n ' -%} 16{%- set ns = namespace(system_prompt='', is_first_sp=true) -%} 17{%- for message in messages -%} 18{%- if message[' role '] == ' system ' -%} 19{%- if ns.is_first_sp -%} 20{%- set ns.system_prompt = ns.system_prompt + (message[' content '] or '') -%} 21{%- set ns.is_first_sp = false -%} 22{%- else -%} 23{%- set ns.system_prompt = ns.system_prompt + ' \ n \ n ' + (message[' content '] or '') -%} 24{%- endif -%} 25{%- endif -%} 26{%- endfor -%} 27{%- if tools is defined and tools -%} 28{%- set ts = namespace(schemas='') -%} 29{%- for tool in tools -%} 30{%- if tool[' type '] == ' function ' -%} 31{%- set ts.schemas = ts.schemas + (tool[' function '] | tojson) + ' \ n ' -%} 32{%- endif -%} 33{%- endfor -%} 34{%- if ns.system_prompt -%} 35{%- set ns.system_prompt = ns.system_prompt + ' \ n \ n ' + tools_header + ts.schemas + tools_footer -%} 36{%- else -%} 37{%- set ns.system_prompt = tools_header + ts.schemas + tools_footer -%} 38{%- endif -%} 39{%- endif -%} 40{{- bos_token -}} 41{{- ns.system_prompt -}} 42{%- set last_user_idx = namespace(value=-1) -%} 43{%- for message in messages -%} 44{%- if message[' role '] == ' user ' or message[' role '] == ' developer ' -%} 45{%- set last_user_idx.value = loop.index0 -%} 46{%- endif -%} 47{%- endfor -%} 48{%- set state = namespace(pending_asst_marker=false, pending_tool_marker=false) -%} 49{%- for message in messages -%} 50{%- if message[' role '] == ' user ' -%} 51{{- ' <| User |> ' + (message[' content '] or '') -}} 52{%- set state.pending_asst_marker = true -%} 53{%- set state.pending_tool_marker = false -%} 54{%- elif message[' role '] == ' assistant ' -%} 55{%- set is_after_last_user = loop.index0 > last_user_idx.value -%} 56{%- if state.pending_asst_marker -%} 57{{- ' <| Assistant |> ' -}} 58{%- if is_after_last_user and thinking -%} 59{{- thinking_start_token -}} 60{%- if message[' reasoning_content '] is defined and message[' reasoning_content '] -%} 61{{- message[' reasoning_content '] -}} 62{%- endif -%} 63{{- thinking_end_token -}} 64{%- else -%} 65{{- thinking_end_token -}} 66{%- endif -%} 67{%- elif state.pending_tool_marker -%} 68{%- if is_after_last_user and thinking -%} 69{{- ' \ n \ n ' + thinking_start_token -}} 70{%- if message[' reasoning_content '] is defined and message[' reasoning_content '] -%} 71{{- message[' reasoning_content '] -}} 72{%- endif -%} 73{{- thinking_end_token -}} 74{%- else -%} 75{{- ' \ n \ n ' + thinking_end_token -}} 76{%- endif -%} 77{%- endif -%} 78{%- set state.pending_asst_marker = false -%} 79{%- set state.pending_tool_marker = false -%} 80{%- if message[' content '] is defined and message[' content '] -%} 81{{- message[' content '] -}} 82{%- endif -%} 83{%- if message[' tool_calls '] -%} 84{{- ' \ n \ n < ' + dsml_token + ' function_calls >\ n ' -}} 85{%- for tool in message[' tool_calls '] -%} 86{%- set func = tool[' function '] -%} 87{{- ' < ' + dsml_token + ' invoke name = "' + func [ 'name' ] + '" >\ n ' -}} 88{%- set args = func[' arguments '] -%} 89{%- if args is string -%} 90{%- set args = args | from_json -%} 91{%- endif -%} 92{%- for key, val in args.items() -%} 93{%- if val is string -%} 94{{- ' < ' + dsml_token + ' parameter name = "' + key + '" string = "true" > ' + val + ' </ ' + dsml_token + ' parameter >\ n ' -}} 95{%- else -%} 96{{- ' < ' + dsml_token + ' parameter name = "' + key + '" string = "false" > ' + (val | tojson) + ' </ ' + dsml_token + ' parameter >\ n ' -}} 97{%- endif -%} 98{%- endfor -%} 99{{- ' </ ' + dsml_token + ' invoke >\ n ' -}} 100{%- endfor -%} 101{{- ' </ ' + dsml_token + ' function_calls > ' -}} 102{%- endif -%} 103{{- ' <| end ▁ of ▁ sentence |> ' -}} 104{%- elif message[' role '] == ' tool ' -%} 105{%- set outer_index = loop.index0 -%} 106{%- set assistant_idx = namespace(value=-1) -%} 107{%- for prev_msg in messages -%} 108{%- if prev_msg[' role '] == ' assistant ' and prev_msg[' tool_calls '] and loop.index0 < outer_index -%} 109{%- set assistant_idx.value = loop.index0 -%} 110{%- endif -%} 111{%- endfor -%} 112{%- set call_order = outer_index - assistant_idx.value -%} 113{%- set assistant_msg = messages[assistant_idx.value] -%} 114{%- set tool_call_count = assistant_msg[' tool_calls '] | length -%} 115{%- if call_order == 1 -%} 116{{- ' \ n \ n < function_results > ' -}} 117{%- endif -%} 118{{- ' \ n < result > ' + (message[' content '] or '') + ' </ result > ' -}} 119{%- if call_order == tool_call_count -%} 120{{- ' \ n </ function_results > ' -}} 121{%- set state.pending_asst_marker = false -%} 122{%- set state.pending_tool_marker = true -%} 123{%- endif -%} 124{%- endif -%} 125{%- endfor -%} 126{%- if add_generation_prompt -%} 127{%- if state.pending_asst_marker -%} 128{{- ' <| Assistant |> ' -}} 129{%- if thinking -%} 130{{- thinking_start_token -}} 131{%- else -%} 132{{- thinking_start_token + thinking_end_token -}} 133{%- endif -%} 134{%- elif state.pending_tool_marker -%} 135{%- if thinking -%} 136{{- ' \ n \ n ' + thinking_start_token -}} 137{%- else -%} 138{{- ' \ n \ n' + thinking_start_token + thinking_end_token -}} 139{% - endif -%} 140{%- endif -%} 141{%- endif -%}