Motif-Technologies/Motif-3-Beta · Hugging Face
Log In<br>Sign Up
","eos_token":"","pad_token":""},"chat_template_jinja":"{%- macro visible_text(content) -%}\n {%- if content is string -%}\n {{- content -}}\n {%- elif content is iterable and content is not mapping -%}\n {%- for item in content -%}\n {%- if item is mapping and item.type == 'text' -%}\n {{- item.text -}}\n {%- elif item is string -%}\n {{- item -}}\n {%- endif -%}\n {%- endfor -%}\n {%- else -%}\n {{- content -}}\n {%- endif -%}\n{%- endmacro -%}\n\n{{- '' -}}\n\n{%- set ns = namespace(has_system=false, last_user_index=-1, last_assistant_index=-1) -%}\n{%- if messages | length > 0 and messages[0].role == 'system' -%}\n {%- set ns.has_system = true -%}\n{%- endif -%}\n{%- for m in messages -%}\n {%- if m.role == 'user' -%}\n {%- set ns.last_user_index = loop.index0 -%}\n {%- elif m.role == 'assistant' -%}\n {%- set ns.last_assistant_index = loop.index0 -%}\n {%- endif -%}\n{%- endfor -%}\n\n{#- ── System / Tools block ── -#}\n{%- if tools is iterable and tools | length > 0 -%}\n {{- '' -}}\n {{- '# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\n' -}}\n {{- 'You are provided with function signatures within XML tags:\\n\\n' -}}\n {%- for tool in tools -%}\n {%- if tool.function is defined -%}\n {%- set tool = tool.function -%}\n {%- endif -%}\n {{- '\\n' ~ (tool | tojson) -}}\n {%- endfor -%}\n {{- '\\n' -}}\n {{- '\\n\\nFor each function call, output in JSON within tags:\\n' -}}\n {%- for tool in tools -%}\n {%- if tool.function is defined -%}\n {%- set tool = tool.function -%}\n {%- endif -%}\n {%- set _props = tool.parameters.properties if (tool.parameters is defined and tool.parameters.properties is defined) else {} -%}\n {{- '\\n{\"name\": \"' ~ tool.name ~ '\", \"arguments\": {' -}}\n {%- set _keys = _props | list -%}\n {%- for k in _keys -%}\n {{- '\"' ~ k ~ '\": ' -}}\n {%- if not loop.last -%}{{- ', ' -}}{%- endif -%}\n {%- endfor -%}\n {{- '}}' -}}\n {%- endfor -%}\n {%- if ns.has_system -%}\n {{- '\\n\\n' ~ visible_text(messages[0].content) -}}\n {%- endif -%}\n {{- '' -}}\n{%- elif ns.has_system -%}\n {{- '' ~ visible_text(messages[0].content) ~ '' -}}\n{%- endif -%}\n\n{#- ── Conversation turns ── -#}\n{%- for m in messages -%}\n\n {#- [Fix 1] continue 대신 if/elif 체인으로 첫 system 스킵 -#}\n {%- if loop.index0 == 0 and m.role == 'system' -%}\n {#- already rendered above, skip -#}\n\n {#- [Fix 2] 중간에 나오는 system 메시지도 처리 -#}\n {%- elif m.role == 'system' -%}\n {{- '' ~ visible_text(m.content) ~ '' -}}\n\n {%- elif m.role == 'user' -%}\n {{- '' -}}\n {%- if m.references is defined and m.references -%}\n {{- '' ~ m.references ~ '\\n' -}}\n {%- endif -%}\n {{- visible_text(m.content) -}}\n {{- '' -}}\n\n {%- elif m.role == 'assistant' -%}\n {{- '' -}}\n\n {#- [순서 정책] think → plan → content → tool_calls -#}\n\n {#- Reasoning block -#}\n {%- set _content = visible_text(m.content) -%}\n {%- set _reasoning = '' -%}\n {%- if m.reasoning_content is string -%}\n {%- set _reasoning = m.reasoning_content -%}\n {%- elif '' in _content -%}\n {%- set _reasoning = _content.split('')[0].split('')[-1].strip() -%}\n {%- set _content = _content.split('', 1)[-1].lstrip('\\n') -%}\n {%- endif -%}\n {%- set _has_tools = (tools is defined and tools is iterable and tools | length > 0) -%}\n {%- set _emit_think = _reasoning and (_has_tools or loop.index0 == ns.last_assistant_index) -%}\n {%- if _emit_think -%}\n {{- '' ~ _reasoning.strip() ~ '' -}}\n {%- endif -%}\n\n {#- Text content -#}\n {%- if _content.strip() -%}\n {{- _content.strip() -}}\n {%- endif -%}\n\n {#- Tool calls — IDs are rendered for intermediate assistant turns\n (context for call↔response correlation) but omitted for the last\n assistant turn (prediction target — model should not learn to\n generate IDs). After multi-turn data expansion, intermediate turns\n become GRAY context and the last turn is GREEN. -#}\n {%- if m.tool_calls is defined and m.tool_calls -%}\n {%- set _is_last_assistant = (loop.index0 == ns.last_assistant_index) and not add_generation_prompt -%}\n {%- for tc in m.tool_calls -%}\n {%- set _tc_id = tc.id if (tc.id is defined and not _is_last_assistant) else none -%}\n {%- if tc.function is defined -%}\n {%- set tc = tc.function -%}\n {%- endif -%}\n {%- set _id_suffix = ', \"id\": ' ~ (_tc_id | tojson) if _tc_id is not none else '' -%}\n {%- if tc.arguments is not defined or not tc.arguments or tc.arguments == \"\" -%}\n {{- '\\n' ~ '{\"name\": \"' ~ tc.name ~ '\", \"arguments\": ' ~ null ~ _id_suffix ~ '}' ~ '' -}}\n {%- elif tc.arguments is string -%}\n {{- '\\n' ~ '{\"name\": \"' ~ tc.name ~ '\", \"arguments\": ' ~ tc.arguments ~ _id_suffix ~ '}' ~ '' -}}\n {%- else -%}\n {{- '\\n' ~ '{\"name\": \"' ~ tc.name ~ '\", \"arguments\": ' ~ (tc.arguments | tojson) ~ _id_suffix ~ '}' ~ '' -}}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n\n {{- '' -}}\n\n {%- elif m.role == 'tool' -%}\n {#- [Fix 3] loop.previtem/nextitem으로 인덱스 오버플로 제거 -#}\n {%-...