j2prompt-lint/jinja2-prompt-template-corpus huggingface dataset:
{%- set today = strftime_now("%Y-%m-%d") %}
{%- set default_think_system_message = "You are a helpful assistant. Think deeply before answering the user's question. Do the thinking inside <think>...</think> tags." %}
{%- set default_nothink_system_message = "You are a helpful assistant." %}
{%- set think_system_message_addition = "Think deeply before answering the user's question. Do the thinking inside <think>...</think> tags." %}

{{- bos_token }}

{%- if messages[0].role == 'system' %}
    {%- if enable_thinking is defined and enable_thinking is false %}
        {%- set system_message = messages[0].content %}
    {%- else %}
        {%- set system_message = think_system_message_addition +'\n\n'+ messages[0].content %}
    {%- endif %}
    {%- set loop_messages = messages[1:] %}
{%- else %}
    {%- if enable_thinking is defined and enable_thinking is false %}
        {%- set system_message = default_nothink_system_message %}
    {%- else %}
        {%- set system_message = default_think_system_message %}
    {%- endif %}
    {%- set loop_messages = messages %}
{%- endif %}

{{- '[SYSTEM_PROMPT]' + system_message + '[/SYSTEM_PROMPT]' }}

{%- for message in loop_messages %}
    {%- if message.role == 'user' %}
        {%- if loop.index0 % 2 == 1 %}
            {{- raise_exception('User and assistant turns must alternate starting with user turn!') }}
        {%- endif %}
        {%- if loop.last and not (enable_thinking is defined and enable_thinking is false) %}
            {{- '
' + message.content + '
<think>\n' }}
        {%- else %}
            {{- '
' + message.content + '
' }}
        {%- endif %}
    {%- elif message.role == 'system' %}
        {{- raise_exception('System message can only be the first message!') }}
    {%- elif message.role == 'assistant' %}
        {%- if loop.index0 % 2 == 0 %}
            {{- raise_exception('User and assistant turns must alternate starting with user turn!') }}
        {%- endif %}
        {%- set content = message.content %}
        {%- set reasoning_content = '' %}
        {%- if message.reasoning_content is defined and message.reasoning_content is not none %}
            {%- set reasoning_content = message.reasoning_content %}
        {%- else %}
            {%- if '</think>' in message.content %}
                {%- set content = message.content.split('</think>')[-1].lstrip('\n') %}
                {%- set reasoning_content = message.content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
            {%- endif %}
        {%- endif %}
        {%- if loop.last and reasoning_content and not (enable_thinking is defined and enable_thinking is false) %}
            {{- '<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') + eos_token }}
        {%- else %}
            {{- content + eos_token }}
        {%- endif %}
    {%- else %}
        {{- raise_exception('Only user, system and assistant roles are supported!') }}
    {%- endif %}
{%- endfor %}
{%- if messages[0]['role'] == 'system' %}
    {%- set system_message = messages[0]['content'] %}
    {%- set loop_messages = messages[1:] %}
{%- else %}
    {%- set loop_messages = messages %}
{%- endif %}

{{- bos_token }}
{%- for message in loop_messages %}
    {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}
        {{- raise_exception('After the optional system message, conversation roles must alternate user/assistant/user/assistant/...') }}
    {%- endif %}
    {%- if message['role'] == 'user' %}
        {%- if loop.first and system_message is defined %}
            {{- '
' + system_message + '\n\n' + message['content'] + '
' }}
        {%- else %}
            {{- '
' + message['content'] + '
' }}
        {%- endif %}
    {%- elif message['role'] == 'assistant' %}
        {{- message['content'] + eos_token}}
    {%- else %}
        {{- raise_exception('Only user and assistant roles are supported, with the exception of an initial optional system message!') }}
    {%- endif %}
{%- endfor %}