Team Ai
Modelpublic

Tech2wild/GLM-5.3-Int4-Int8Mix

sourceHugging Faceotherupdated 1mo agoView on Hugging Face
16likes1.6kdownloads
chat_template.jinja252 linesDownload Raw Back to root
1[gMASK]<sop>2{%- set effective_reasoning_effort = reasoning_effort if reasoning_effort is defined and reasoning_effort in ['low', 'high'] else 'max' -%}3{%- if effective_reasoning_effort is not none -%}<|system|>Reasoning Effort: {{ effective_reasoning_effort | capitalize }}{%- endif -%}4{%- set clear_thinking = clear_thinking if clear_thinking is defined else false -%}5{%- if tools -%}6{%- macro tool_to_json(tool) -%}7    {%- set ns_tool = namespace(first=true) -%}8    {{ '{' -}}9    {%- for k, v in tool.items() -%}10        {%- if k != 'defer_loading' and k != 'strict' -%}11            {%- if not ns_tool.first -%}{{- ', ' -}}{%- endif -%}12            {%- set ns_tool.first = false -%}13            "{{ k }}": {{ v | tojson(ensure_ascii=False) }}14        {%- endif -%}15    {%- endfor -%}16    {{- '}' -}}17{%- endmacro -%}18{%- macro tool_references_to_response(refs) -%}19    {{- '<tool_response><tools>\n' -}}20    {%- for tr in refs -%}21        {%- for tool in tools -%}22            {%- if 'function' in tool -%}23                {%- set tool = tool['function'] -%}24            {%- endif -%}25            {%- if tool.name == tr.name -%}26                {{- tool_to_json(tool) + '\n' -}}27            {%- endif -%}28        {%- endfor -%}29    {%- endfor -%}30    {{- '</tools></tool_response>' -}}31{%- endmacro -%}32<|system|>33# Tools34 35You may call one or more functions to assist with the user query.36 37You are provided with function signatures within <tools></tools> XML tags:38<tools>39{% for tool in tools %}40{%- if 'function' in tool -%}41    {%- set tool = tool['function'] -%}42{%- endif -%}43{% if tool.defer_loading is not defined or not tool.defer_loading %}44{{ tool_to_json(tool) }}45{% endif %}46{% endfor %}47</tools>48 49For each function call, output the function name and arguments within the following XML format:50<tool_call>{function-name}<arg_key>{arg-key-1}</arg_key><arg_value>{arg-value-1}</arg_value><arg_key>{arg-key-2}</arg_key><arg_value>{arg-value-2}</arg_value>...</tool_call>{%- endif -%}51{%- macro visible_text(content) -%}52    {%- if content is string -%}53        {{- content }}54    {%- elif content is iterable and content is not mapping -%}55        {%- for item in content -%}56            {%- if item is mapping and item.type == 'text' -%}57                {{- item.text }}58            {%- elif item is string -%}59                {{- item }}60            {%- elif item is mapping and item.type in ['image', 'image_url', 'video', 'video_url', 'audio', 'audio_url', 'input_audio'] -%}61                {%- set media_type = item.type | replace('_url', '') | replace('input_', '') -%}62                {{- "<reminder>You are unable to process this " ~ media_type ~ " because you don't have multi-modal input ability. Try different methods.</reminder>" }}63            {%- endif -%}64        {%- endfor -%}65    {%- else -%}66        {{- content }}67    {%- endif -%}68{%- endmacro -%}69{%- macro tool_response(text) -%}70{{- '<tool_response>' + text + '</tool_response>' -}}71{%- endmacro -%}72{%- macro render_tool_response(m) -%}73{%- if m.content is string -%}74    {{- tool_response(m.content) -}}75{%- elif m.content and m.content is not mapping and m.content.0.type == "tool_reference" -%}76    {{- tool_references_to_response(m.content) -}}77{%- elif is_list_of_outputs(m) -%}78    {%- for tr in m.content -%}79        {%- if tr.output is iterable and tr.output is not string and tr.output is not mapping and tr.output and tr.output.0.type == "tool_reference" -%}80            {{- tool_references_to_response(tr.output) -}}81        {%- else -%}82            {{- tool_response(visible_text(tr.output)) -}}83        {%- endif -%}84    {%- endfor -%}85{%- else -%}86    {{- tool_response(visible_text(m.content)) -}}87{%- endif -%}88{%- endmacro -%}89{%- macro id_of(obj) -%}90    {%- if obj.tool_call_id -%}91        {{- obj.tool_call_id -}}92    {%- elif obj.id -%}93        {{- obj.id -}}94    {%- endif -%}95{%- endmacro -%}96{%- macro is_list_of_outputs(m) -%}97    {%- if m.content and m.content.0.output is defined -%}1{%- endif -%}98{%- endmacro -%}99{%- macro has_dup_tool_result_id(lo, hi, target) -%}100    {%- set ns_cnt = namespace(n=0) -%}101    {%- for k in range(lo, hi + 1) -%}102        {%- set m = messages[k] -%}103        {%- if is_list_of_outputs(m) -%}104            {%- for entry in m.content -%}105                {%- if id_of(entry) == target -%}106                    {%- set ns_cnt.n = ns_cnt.n + 1 -%}107                {%- endif -%}108            {%- endfor -%}109        {%- elif id_of(m) == target -%}110            {%- set ns_cnt.n = ns_cnt.n + 1 -%}111        {%- endif -%}112        {%- if ns_cnt.n > 1 -%}{%- break -%}{%- endif -%}113    {%- endfor -%}114    {%- if ns_cnt.n > 1 -%}1{%- endif -%}115{%- endmacro -%}116{%- macro tc_id_exists(tcs, target) -%}117    {%- set ns_f = namespace(found=false) -%}118    {%- for tc in tcs -%}119        {%- if id_of(tc) == target -%}120            {%- set ns_f.found = true -%}121            {%- break -%}122        {%- endif -%}123    {%- endfor -%}124    {%- if ns_f.found -%}1{%- endif -%}125{%- endmacro -%}126{%- set ns = namespace(last_user_index=-1) -%}127{%- for m in messages %}128    {%- if m.role == 'user' %}129        {%- set ns.last_user_index = loop.index0 -%}130    {%- endif %}131{%- endfor %}132{%- for m in messages -%}133{%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}134{%- elif m.role == 'assistant' -%}135<|assistant|>136{%- set content = visible_text(m.content) %}137{%- if m.reasoning_content is string %}138    {%- set reasoning_content = m.reasoning_content %}139{%- elif '</think>' in content %}140    {%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] %}141    {%- set content = content.split('</think>')[-1] %}142{%- endif %}143{%- if (not clear_thinking or loop.index0 > ns.last_user_index) and reasoning_content is defined -%}144{{ '<think>' + reasoning_content +  '</think>'}}145{%- else -%}146{{ '<think></think>' }}147{%- endif -%}148{%- if content.strip() -%}149{{ content.strip() }}150{%- endif -%}151{% if m.tool_calls %}152{% for tc in m.tool_calls %}153{%- if tc.function %}154    {%- set tc = tc.function %}155{%- endif %}156{{- '<tool_call>' + tc.name -}}157{% set _args = tc.arguments %}{% for k, v in _args.items() %}<arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>{% endfor %}</tool_call>{% endfor %}158{% endif %}159{%- elif m.role == 'tool' -%}160{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}161    {{- '<|observation|>' -}}162    {%- set block_start = loop.index0 -%}163    {%- set ns_blk = namespace(end=block_start) -%}164    {%- for j in range(block_start, messages|length) -%}165        {%- if messages[j].role == 'tool' -%}166            {%- set ns_blk.end = j -%}167        {%- else -%}168            {%- break -%}169        {%- endif -%}170    {%- endfor -%}171    {%- set ns_a = namespace(tool_calls=none) -%}172    {%- if block_start > 0 and messages[block_start - 1].role == 'assistant' and messages[block_start - 1].tool_calls -%}173        {%- set ns_a.tool_calls = messages[block_start - 1].tool_calls -%}174    {%- endif -%}175    {%- set ns_chk = namespace(can_sort=true) -%}176    {%- if not ns_a.tool_calls -%}177        {%- set ns_chk.can_sort = false -%}178    {%- else -%}179        {%- for k in range(block_start, ns_blk.end + 1) -%}180            {%- set m = messages[k] -%}181            {%- if is_list_of_outputs(m) -%}182                {%- for entry in m.content -%}183                    {%- set eid = id_of(entry) -%}184                    {%- if not eid -%}185                        {%- set ns_chk.can_sort = false -%}186                    {%- elif has_dup_tool_result_id(block_start, ns_blk.end, eid) -%}187                        {%- set ns_chk.can_sort = false -%}188                    {%- elif not tc_id_exists(ns_a.tool_calls, eid) -%}189                        {%- set ns_chk.can_sort = false -%}190                    {%- endif -%}191                {%- endfor -%}192            {%- else -%}193                {%- set tk_id = id_of(m) -%}194                {%- if not tk_id -%}195                    {%- set ns_chk.can_sort = false -%}196                {%- elif has_dup_tool_result_id(block_start, ns_blk.end, tk_id) -%}197                    {%- set ns_chk.can_sort = false -%}198                {%- elif not tc_id_exists(ns_a.tool_calls, tk_id) -%}199                    {%- set ns_chk.can_sort = false -%}200                {%- endif -%}201            {%- endif -%}202        {%- endfor -%}203        {%- for i in range(ns_a.tool_calls | length) -%}204            {%- set tc_id = id_of(ns_a.tool_calls[i]) -%}205            {%- if not tc_id -%}206                {%- set ns_chk.can_sort = false -%}207            {%- endif -%}208            {%- for j in range(i + 1, ns_a.tool_calls | length) -%}209                {%- if id_of(ns_a.tool_calls[j]) == tc_id -%}210                    {%- set ns_chk.can_sort = false -%}211                {%- endif -%}212            {%- endfor -%}213        {%- endfor -%}214    {%- endif -%}215    {%- if ns_chk.can_sort -%}216        {%- for tc in ns_a.tool_calls -%}217            {%- set tc_id = id_of(tc) -%}218            {%- for k in range(block_start, ns_blk.end + 1) -%}219                {%- set m = messages[k] -%}220                {%- if is_list_of_outputs(m) -%}221                    {%- for entry in m.content -%}222                        {%- set eid = id_of(entry) -%}223                        {%- if eid == tc_id -%}224                            {%- if entry.output is iterable and entry.output is not string and entry.output is not mapping and entry.output and entry.output.0.type == "tool_reference" -%}225                                {{- tool_references_to_response(entry.output) -}}226                            {%- else -%}227                                {{- tool_response(visible_text(entry.output)) -}}228                            {%- endif -%}229                        {%- endif -%}230                    {%- endfor -%}231                {%- else -%}232                    {%- set tk_id = id_of(m) -%}233                    {%- if tk_id == tc_id -%}234                        {{- render_tool_response(m) -}}235                    {%- endif -%}236                {%- endif -%}237            {%- endfor -%}238        {%- endfor -%}239    {%- else -%}240        {%- for k in range(block_start, ns_blk.end + 1) -%}241            {{- render_tool_response(messages[k]) -}}242        {%- endfor -%}243    {%- endif -%}244{% endif -%}245{%- elif m.role == 'system' -%}246<|system|>{{ visible_text(m.content) }}247{%- endif -%}248{%- endfor -%}249{%- if add_generation_prompt -%}250    <|assistant|>{%- if enable_thinking is defined and not enable_thinking -%}{{- '<think></think>' -}}{%- else -%}{{- '<think>' -}}{%- endif -%}251{%- endif -%}252