char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
0b1bad14f
char/aliceai-t5-moe
1{# 2Template: Muse Glimmer ATEM Chat Template 3Renders the ATEM tool-calling protocol: reasoning channel (to=self), tool 4channels (to=<tool>), and the user channel, plus tool definitions and the 5valid-recipient list in the system block. 6 7Whitespace note: every tag uses the {%- -%} / {{- -}} stripping markers, so 8the indentation below is purely for readability and contributes nothing to 9the rendered output. 10#} 11{%- macro render_content ( content ) - %} 12{%- if content is string -%} 13{{ - content - }} 14{%- elif content is not none -%} 15{%- for part in content -%} 16{%- if part [ 'type' ] == 'image' -%} 17{{ - '<|patch|>' - }} 18{%- elif part [ 'type' ] == 'video' -%} 19{{ - '<|video|>' - }} 20{%- elif part [ 'type' ] == 'text' -%} 21{{ - part [ 'text' ] - }} 22{%- endif -%} 23{%- endfor -%} 24{%- endif -%} 25{%- endmacro -%} 26{%- macro render_atem ( tc ) - %} 27{%- set args = tc . function . arguments -%} 28{%- if args is not mapping -%} 29{{ - raise_exception ( 'Muse Glimmer ATEM chat template requires tool_call.function.arguments to be a dict (mapping); a JSON string cannot be parsed in the HF jinja sandbox.' ) - }} 30{%- endif -%} 31{{ - '<atem:function_calls>\n<atem:invoke name="' + tc.function.name + '">\n' - }} 32{%- for k , v in args . items () - %} 33{{ - '<atem:parameter name="' + k + '">' - }} 34{%- if v is boolean -%} 35{%- if v -%} 36 true 37{%- else -%} 38 false 39{%- endif -%} 40{%- elif v is none -%} 41 null 42{%- elif v is mapping or ( v is iterable and v is not string ) - %} 43{{ - v | tojson - }} 44{%- else -%} 45{{ - v - }} 46{%- endif -%} 47{{ - '</atem:parameter>\n' - }} 48{%- endfor -%} 49{{ - '</atem:invoke>\n</atem:function_calls>' - }} 50{%- endmacro -%} 51{%- macro render_tool_defs ( tools ) - %} 52{{ - 'In this environment you have access to a set of tools you can use to answer the user\' s question .\ n \ n ' -}} 53{{- ' You can invoke a function by writing a "<atem:function_calls>" block like the following :\ n ' -}} 54{{- ' < atem : function_calls >\ n < atem : invoke name = "$FUNCTION_NAME" >\ n < atem : parameter name = "$PARAMETER_NAME" >$ PARAMETER_VALUE </ atem : parameter >\ n ...\ n </ atem : invoke >\ n </ atem : function_calls >\ n \ n ' -}} 55{{- ' String and scalar parameters should be specified as is , while lists and objects should use JSON format . Note that spaces for string values are not stripped . The output is not expected to be valid XML and is parsed with regular expressions .\ n ' -}} 56{{- ' Here are the functions available in JSONSchema format :\ n ' -}} 57{{- ' // Tool metadata \ n ' -}} 58{%- set nsns = namespace(seen=[]) -%} 59{%- for tool in tools -%} 60{%- set fn = tool.function if tool.function is defined else tool -%} 61{%- set tns = fn.name.split(' . ')[0] -%} 62{%- if tns not in nsns.seen -%} 63{%- set nsns.seen = nsns.seen + [tns] -%} 64{%- endif -%} 65{%- endfor -%} 66{%- set nd = tool_namespace_descriptions if tool_namespace_descriptions is defined else {} -%} 67{%- for tns in nsns.seen -%} 68{{- '{"name" : ' + (tns | tojson) + ' , "description" : ' + ((nd[tns] if tns in nd else '') | tojson) + '} \ n ' -}} 69{%- endfor -%} 70{{- ' // Function schemas ' -}} 71{%- for tool in tools -%} 72{%- set fn = tool.function if tool.function is defined else tool -%} 73{{- ' \ n {"name" : ' + (fn.name | tojson) + ' , "description" : ' + (fn.description | tojson) + ' , "parameters" : ' + (fn.parameters | tojson) + '}' -}} 74{%- endfor -%} 75{{- ' \ n \ nHere \ 's an example of how to call a function in the tool set:\n' - }} 76{{ - '(If the tool namespace is not specified, invoke the function directly as `example_function_name` rather than `example_tool_name.example_function_name`)\n\n' - }} 77{{ - 'to=example_tool_name.example_function_name\n\n' - }} 78{{ - '<atem:function_calls>\n<atem:invoke name=" example_tool_name . example_function_name ">\n' - }} 79{{ - '<atem:parameter name=" example_parameter_1 ">value_1</atem:parameter>\n' - }} 80{{ - '<atem:parameter name=" example_parameter_2 ">This is the value for the second parameter\nthat can span\n" multiple " lines\n</atem:parameter>\n' - }} 81{{ - '</atem:invoke>\n</atem:function_calls>' - }} 82{%- endmacro -%} 83{%- macro render_reasoning () - %} 84{%- set rs = reasoning_strength if reasoning_strength is defined and reasoning_strength else 'high' -%} 85{{ - 'Reasoning strength: ' + rs + '.' - }} 86{%- endmacro -%} 87{%- macro render_system_meta ( tools ) - %} 88{%- set rns = namespace ( recipients =[ '" self "' ], nslist =[]) - %} 89{%- if tools -%} 90{%- for tool in tools -%} 91{%- set fn = tool . function if tool . function is defined else tool -%} 92{%- set tns = fn . name . split ( '.' )[ 0 ] - %} 93{%- if tns not in rns . nslist -%} 94{%- set rns . nslist = rns . nslist + [ tns ] - %} 95{%- endif -%} 96{%- endfor -%} 97{%- for tns in rns . nslist -%} 98{%- set rns . recipients = rns . recipients + [ '"' + tns + ' .* "' ] - %} 99{%- endfor -%} 100{%- endif -%} 101{%- set rns . recipients = rns . recipients + [ '" user "' ] - %} 102{{ - '# Valid recipients: ' + rns . recipients | join ( ', ' ) + '.' - }} 103{%- endmacro -%} 104{{ - bos_token - }} 105{%- set ns = namespace ( has_system = false ) - %} 106{%- for m in messages -%} 107{%- if m [ 'role' ] == 'system' -%} 108{%- set ns . has_system = true -%} 109{%- endif -%} 110{%- endfor -%} 111{%- if not ns . has_system -%} 112{{ - '<|start|>system<|message|>You are a helpful AI assistant.' - }} 113{%- set kc = knowledge_cutoff if knowledge_cutoff is defined and knowledge_cutoff else '2026-01-04' -%} 114{{ - '\nKnowledge cutoff: ' + kc + '.' - }} 115{%- if current_date is defined and current_date -%} 116{{ - '\nCurrent date: ' + current_date + '.' - }} 117{%- elif strftime_now is defined -%} 118{{ - '\nCurrent date: ' + strftime_now ( '%Y-%m-%d' ) + '.' - }} 119{%- endif -%} 120{{ - '\n\n' - }} 121{{ - render_reasoning () - }} 122{%- if tools -%} 123{{ - '\n\n' - }} 124{{ - render_tool_defs ( tools ) - }} 125{%- endif -%} 126{{ - '\n\n' - }} 127{{ - render_system_meta ( tools ) - }} 128{{ - '<|eot|>' - }} 129{%- endif -%} 130{%- for message in messages -%} 131{%- set role = message [ 'role' ] - %} 132{%- set end_token = '<|eom|>' if ( not loop . last and messages [ loop . index0 + 1 ][ 'role' ] == role ) else '<|eot|>' -%} 133{%- if role == 'system' -%} 134{#- Callers sometimes write the directive into the system prompt themselves. 135Normalise "Reasoning effort" to "Reasoning strength" (jinja has no 136case-insensitive replace, hence the four realistic casings), then skip 137the kwarg-driven line below if the prompt already carries one. -#} 138{%- set sys_text = render_content ( message [ 'content' ]) 139| replace ( 'Reasoning effort' , 'Reasoning strength' ) 140| replace ( 'Reasoning Effort' , 'Reasoning Strength' ) 141| replace ( 'reasoning effort' , 'reasoning strength' ) 142| replace ( 'REASONING EFFORT' , 'REASONING STRENGTH' ) - %} 143{{ - '<|start|>system<|message|>' - }} 144{{ - sys_text - }} 145{%- if 'reasoning strength' not in ( sys_text | lower ) - %} 146{{ - '\n\n' - }} 147{{ - render_reasoning () - }} 148{%- endif -%} 149{%- if tools -%} 150{{ - '\n\n' - }} 151{{ - render_tool_defs ( tools ) - }} 152{%- endif -%} 153{{ - '\n\n' - }} 154{{ - render_system_meta ( tools ) - }} 155{{ - '<|eot|>' - }} 156{%- elif role == 'user' -%} 157{{ - '<|start|>user<|message|>' - }} 158{{ - render_content ( message [ 'content' ]) - }} 159{{ - '<|eot|>' - }} 160{%- elif role == 'tool' -%} 161{%- set tname = message . get ( 'name' ) - %} 162{%- if not tname -%} 163{%- set tcid = message . get ( 'tool_call_id' ) - %} 164{%- set rns = namespace ( name = tcid if tcid else '' ) - %} 165{%- for m in messages -%} 166{%- if m . get ( 'tool_calls' ) - %} 167{%- for tc in m [ 'tool_calls' ] - %} 168{%- if tcid is not none and tc . id is defined and tc . id == tcid -%} 169{%- set rns . name = tc . function . name -%} 170{%- endif -%} 171{%- endfor -%} 172{%- endif -%} 173{%- endfor -%} 174{%- set tname = rns . name -%} 175{%- endif -%} 176{{ - '<|start|>tool ' + tname + '<|message|><tool_output name="' + tname + '">\n' - }} 177{{ - render_content ( message [ 'content' ]) - }} 178{{ - '\n</tool_output><|eot|>' - }} 179{%- elif role == 'assistant' -%} 180{%- if message . get ( 'reasoning_content' ) - %} 181{{ - '<|start|>assistant to=self<|message|>' + message [ 'reasoning_content' ] + '<|eom|>' - }} 182{%- endif -%} 183{%- if message . get ( 'tool_calls' ) - %} 184{%- for tc in message [ 'tool_calls' ] - %} 185{{ - '<|start|>assistant to=' + tc . function . name + '<|message|>' - }} 186{{ - render_atem ( tc ) - }} 187{%- if loop . last -%} 188{{ - end_token - }} 189{%- else -%} 190{{ - '<|eom|>' - }} 191{%- endif -%} 192{%- endfor -%} 193{%- else -%} 194{%- set recipient = message . get ( 'recipient' ) or 'user' -%} 195{%- set end_turn = message . get ( 'end_turn' ) - %} 196{%- if end_turn is none -%} 197{%- set end_turn = not ( recipient and recipient != 'user' ) - %} 198{%- endif -%} 199{{ - '<|start|>assistant' - }} 200{%- if recipient -%} 201{{ - ' to=' + recipient - }} 202{%- endif -%} 203{{ - '<|message|>' - }} 204{{ - render_content ( message [ 'content' ]) - }} 205{{ - ( '<|eot|>' if end_turn else '<|eom|>' ) - }} 206{%- endif -%} 207{%- endif -%} 208{%- endfor -%} 209{%- if add_generation_prompt -%} 210{{ - '<|start|>assistant' - }} 211{%- endif -%}