A.X-K2-Raon-Speech-21B-A3B / chat_template.jinja
ddwkim's picture
initial commit
8c00b68
Raw
History Blame
4.64 kB
{%- if tools is iterable and tools | length > 0 %}
{{- '<|im_start|>system
당신은 도구 호출 기능을 갖춘 유용한 도우미입니다. 사용자의 요청을 처리하기 위해서 필요한 도구가 주어진 목록에 있는 경우 도구 호출로 응답하세요.
필요한 도구가 목록에 없는 경우에는 도구 호출 없이 사용자가 요구한 정보를 제공하세요.
필요한 도구가 목록에 있지만 해당 도구를 호출하는데 필요한 argument 정보가 부족한 경우 해당 정보를 사용자에게 요청하세요.
사용자의 요청을 처리하기 위해 여러번 도구를 호출할 수 있어야 합니다.
도구 호출 이후 도구 실행 결과를 입력으로 받으면 해당 결과를 활용하여 답변을 생성하세요.
다음은 접근할 수 있는 도구들의 목록 입니다:
<tools>
' }}
{%- for t in tools %}
{{- t | tojson }}
{{- '\n' }}
{%- endfor %}
{{- '</tools>
도구를 호출하려면 아래의 JSON으로 응답하세요.
도구 호출 형식: <tool_call>{"name": 도구 이름, "arguments": dictionary 형태의 도구 인자값}</tool_call><|im_end|>
' }}
{%- endif %}
{%- set ns = namespace(last_user_index=-1) %}
{%- for m in messages %}
{%- if m.role == 'user' %}
{%- set ns.last_user_index = loop.index0 %}
{%- endif %}
{%- endfor %}
{%- for message in messages %}
{%- if message.role == 'system' %}
{{- '<|im_start|>system\n' + message.content + '<|im_end|>\n' }}
{%- elif message.role == 'user' %}
{{- '<|im_start|>user\n' + message.content + '<|im_end|>\n' }}
{%- elif message.role == 'assistant' %}
{{- '<|im_start|>assistant\n' }}
{#- Extract reasoning and content -#}
{%- set reasoning_content = '' %}
{%- set content = '' %}
{%- if message.content is defined %}
{%- set content = message.content %}
{%- endif %}
{%- if message.reasoning_content is defined and message.reasoning_content is not none %}
{%- set reasoning_content = message.reasoning_content %}
{%- elif message.reasoning is defined and message.reasoning is not none %}
{%- set reasoning_content = message.reasoning %}
{%- elif '</think>' in content %}
{%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] %}
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
{%- endif %}
{#- Determine whether to render thinking -#}
{%- set render_thinking = false %}
{%- if reasoning_content %}
{%- if show_thinking is defined and show_thinking %}
{%- set render_thinking = true %}
{%- elif not (show_thinking is defined and not show_thinking) %}
{#- show_thinking undefined: show if last turn or tool-call turn after last user -#}
{%- if loop.last or (message.tool_calls is defined and loop.index0 > ns.last_user_index) %}
{%- set render_thinking = true %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- if render_thinking %}
{{- '<think>' + reasoning_content.strip() + '</think>' }}
{%- else %}
{{- '</think>' }}
{%- endif %}
{{- content }}
{%- if message.tool_calls is defined %}
{%- for tool_call in message.tool_calls %}
{%- set tc_id = tool_call.id | default('') %}
{%- if tool_call.function is defined %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '<tool_call>' + tc_id + '\n' }}
{{- '{"name": "' + tool_call.name + '"' }}
{%- if tool_call.arguments is defined %}
{{- ', "arguments": ' }}
{{- tool_call.arguments | tojson }}
{%- endif %}
{{- '}\n</tool_call>' }}
{%- endfor %}
{%- endif %}
{{- '<|im_end|>' + ('\n' if (not loop.last or add_generation_prompt) else '') }}
{%- elif message.role == 'tool' %}
{{- '<|im_start|>tool\n' }}
{{- '<tool_response>' + (message.tool_call_id | default('')) + '\n' }}
{{- message.content + '\n' }}
{{- '</tool_response><|im_end|>\n' }}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
{{- '<|im_start|>assistant\n' }}
{%- if enable_thinking is defined and enable_thinking is true %}
{{- '<think>' }}
{%- else %}
{{- '</think>' }}
{%- endif %}
{%- endif %}