{# version=v2 #}{%- if not tools -%}
    {%- set tools = [] -%}
{%- endif -%}
{{- bos_token + '<|from|>system\n<|recipient|>all\n<|content|>' + generate_schema_from_functions(tools) -}}
{%- if tools|length > 0 and tools|selectattr("type", "equalto", "code_interpreter")|list|length > 0 -%}
    {{- '\n<|from|>system\n<|recipient|>all\n<|content|>When you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 60.0 seconds. The drive at \'/mnt/data\' can be used to save and persist user files.' -}}
{%- else -%}
    {{- "\n<|from|>system\n<|recipient|>all\n<|content|>A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. The assistant calls functions with appropriate input when necessary" -}}
{%- endif -%}
{%- for message in messages -%}
    {%- if message['role'] == 'user' or message['role'] == 'system' -%}
        {{- '\n<|from|>' + message['role'] + '\n<|recipient|>all\n<|content|>' + message['content'] -}}
    {%- elif message['role'] == 'tool' -%}
        {{- '\n<|from|>' + message['name'] + '\n<|recipient|>all\n<|content|>' + message['content'] -}}
    {%- else -%}
        {% set print_stop = false %}
        {%- if message['content'] and message['content']|length > 0 -%}
            {{- "\n<|from|>" + message['role'] + "\n<|recipient|>all\n<|content|>" + message['content'] -}}
            {% set print_stop = true %}
        {%- endif -%}
        {%- if 'tool_calls' in message and message['tool_calls'] and message['tool_calls']|length > 0 -%}
            {%- for tool_call in message['tool_calls'] -%}
                {{- '\n<|from|>' + message['role'] + '\n<|recipient|>' + tool_call['function']['name'] + '\n<|content|>' + tool_call['function']['arguments'] -}}
            {%- endfor -%}
            {% set print_stop = true %}
        {%- endif -%}
        {%- if print_stop -%}
            {{- "<|stop|>" -}}
        {%- endif -%}
    {%- endif -%}
{%- endfor -%}
{% if add_generation_prompt %}{{- '\n<|from|>assistant\n<|recipient|>' -}}{% endif %}