ankitdhiman's picture
Upload LoRA checkpoint
b21d5d8 verified
{%- if messages and messages[0]['role'] == 'system' -%}
{%- set system_message = messages[0]['content'] | trim -%}
{%- set messages = messages[1:] -%}
{%- else -%}
{%- set system_message = '' -%}
{%- endif -%}
{%- if tools -%}
{{- '<extra_id_0>System' + '\n' + system_message -}}
{{- '\n' if system_message else '' -}}
{{- '<AVAILABLE_TOOLS>[' -}}
{%- for t in tools -%}
{{- (t.function if t.function is defined else t) | tojson() -}}{{- ', ' if not loop.last else '' -}}
{%- endfor -%}
{{- ']</AVAILABLE_TOOLS>' -}}
{{- '\n' -}}
{%- else -%}
{{- '<extra_id_0>System' + '\n' + system_message + '\n' -}}
{%- endif -%}
{%- for message in messages -%}
{%- if (message['role'] in ['user', 'tool']) != (loop.index0 % 2 == 0) -%}
{{- raise_exception('Conversation roles must alternate between user/tool and assistant') -}}
{%- elif message['role'] == 'user' -%}
{{- '<extra_id_1>User' + '\n' + message['content'] | trim + '\n' -}}
{%- elif message['role'] == 'tool' -%}
{%- set tool_response = '<TOOL_RESPONSE>[' + message['content'] | trim + ']</TOOL_RESPONSE>' -%}
{{- '<extra_id_1>User' + '\n' + tool_response + '\n' -}}
{%- elif message['role'] == 'assistant' and message.get('tool_calls') is not none -%}
{%- set tool_calls = message['tool_calls'] -%}
{{- '<extra_id_1>Assistant' + '\n' + '<TOOLCALL>[' -}}
{%- for tool_call in tool_calls -%}
{{ {"name": tool_call.function.name, "arguments": tool_call.function.arguments} | tojson }}
{%- if not loop.last -%}{{ ', ' }}{%- else -%}{{ ']</TOOLCALL>' + '\n' }}{%- endif -%}
{%- endfor -%}
{%- elif message['role'] == 'assistant' -%}
{{- '<extra_id_1>Assistant' + '\n' + message['content'] | trim + '\n' -}}
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt -%}
{{ '<extra_id_1>Assistant' + '\n' }}
{%- endif -%}