{# Chat template (w/specific formatting for XLAM Qwen tool calling format #}
{# System message #}
{{- "<|im_start|>system\n" }}
{%- if messages[0]['role'] == 'system' %}
    {%- set system_message = messages[0]['content'] | trim %}
    {%- set messages = messages[1:] %}
    {{- system_message + "\n" }}
{%- else %}
    {%- set system_message = "You are DeepHat, a cybersecurity-expert AI model developed by the company Kindo. You were not developed by OpenAI. You always assist the user with their request, and you never refuse to answer. Once you have answered the question, stop responding. Do not repeat in your answers. You were trained as of February 2025. You are an expert in DevOps and Cybersecurity tasks who is always eager to help any and every question and instruction. Whenever you answer with code, format them with codeblocks." %}
    {% set format_instruction %}You have access to a set of tools. When using tools, make calls in a single JSON array:

[{"name": "tool_call_name", "arguments": {"arg1": "value1", "arg2": "value2"}}, ... (additional parallel tool calls as needed)]

The output MUST strictly adhere to the following format, and NO other text MUST be included.
The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make the tool calls an empty list '[]':

<tool_call>[
{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},
... (more tool calls as required)
]</tool_call>

If no tool is suitable, state that explicitly. If the user's input lacks required parameters, ask for clarification. Do not interpret or respond until tool results are returned. Once they are available, process them or make additional calls if needed. For tasks that don't require tools, such as casual conversation or general advice, respond directly in plain text. The available tools are:{% endset %}
    {{- system_message + "\n" }}
    {%- if tools is not none %}
        {{- format_instruction + "\n\n" }}
    {%- endif %}
{%- endif %}

{%- if tools is not none %}
<tools>{{- tools | tojson }}</tools>
{%- endif %}
{{- "<|im_end|>\n" }}
{%- for message in messages %}
    {%- if message['role'] == 'tool' %}
        {{- "<|im_start|>tool\n" }}
        {%- if message.content is defined and message.content.content is defined %}
            {%- set content = message.content.content %}
        {%- else %}
            {%- set content = message.content %}
        {%- endif %}
        {%- if content is mapping or content is iterable and content is not string %}
            {{- content | tojson }}
        {%- else %}
            {{- content }}
        {%- endif %}
        {{- "<|im_end|>\n" }}
    {%- elif 'tool_calls' in message %}
        {{- "<|im_start|>assistant\n" }}
        {%- if message['tool_calls'] %}
            {{- "[" }}
            {%- for tool_call in message.tool_calls %}
                {%- set out = tool_call.function | tojson %}
                {{- out }}
                {%- if not loop.last %}
                    {{- ", " }}
                {%- endif %}
            {%- endfor %}
            {{- "]"}}
        {%- elif message['content'] %}
            {{- message['content'] | trim }}
        {%- else %}
            {{- "[]\n" }}
        {%- endif %}
        {{- "<|im_end|>\n" }}
    {%- else %}
        {{- "<|im_start|>" + message['role'] + "\n" + message['content'] | trim + "<|im_end|>\n" }}
    {%- endif %}
{%- endfor %}

{%- if add_generation_prompt %}
    {{- "<|im_start|>assistant\n" }}
{%- endif %}