|
|
{{- bos_token }} |
|
|
{%- if not tools is defined %} |
|
|
{%- set tools = none %} |
|
|
{%- endif %} |
|
|
|
|
|
{%- if messages[0]['role'] in ['system', 'developer'] %} |
|
|
{%- set system_message = messages[0]['content']|trim %} |
|
|
{%- set messages = messages[1:] %} |
|
|
{%- else %} |
|
|
{%- set system_message = "" %} |
|
|
{%- endif %} |
|
|
|
|
|
{{- "<|start_header_id|>system<|end_header_id|> |
|
|
|
|
|
" }} |
|
|
{%- if tools is not none and tools|length > 0 %} |
|
|
{{- "Environment: ipython |
|
|
" }} |
|
|
{{- "You have access to the following functions. To call a function, please respond with JSON for a function call." }} |
|
|
{{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }} |
|
|
{{- "Do not use variables. |
|
|
|
|
|
" }} |
|
|
{%- for t in tools %} |
|
|
{{- t | tojson }} |
|
|
{{- " |
|
|
|
|
|
" }} |
|
|
{%- endfor %} |
|
|
{%- endif %} |
|
|
{{- system_message }} |
|
|
{{- "<|eot_id|>" }} |
|
|
{%- for message in messages %} |
|
|
{%- if not (message.role == 'tool' or 'tool_calls' in message) %} |
|
|
{{- '<|start_header_id|>' + message['role'] + '<|end_header_id|> |
|
|
|
|
|
'+ message['content'] | trim + '<|eot_id|>' }} |
|
|
{%- elif 'tool_calls' in message %} |
|
|
{{- '<|start_header_id|>assistant<|end_header_id|> |
|
|
|
|
|
' -}} |
|
|
{%- for tool_call in message.tool_calls -%} |
|
|
{{- '<|start_tool_call|>' }} |
|
|
{{- '{"name": "' + tool_call.function.name + '", ' }} |
|
|
{{- '"parameters": ' }} |
|
|
{{- tool_call.function.arguments | tojson }} |
|
|
{{- "}" }} |
|
|
{{- '<|end_tool_call|>' }} |
|
|
{%- if not loop.last %}, {% endif %} |
|
|
{%- endfor -%} |
|
|
{{- "<|eot_id|>" }} |
|
|
{%- elif message.role == "tool" %} |
|
|
{{- "<|start_header_id|>ipython<|end_header_id|> |
|
|
|
|
|
" }} |
|
|
{%- if message.content is mapping or message.content is iterable %} |
|
|
{{- message.content | tojson }} |
|
|
{%- else %} |
|
|
{{- message.content }} |
|
|
{%- endif %} |
|
|
{{- "<|eot_id|>" }} |
|
|
{%- endif %} |
|
|
{%- endfor %} |
|
|
{%- if add_generation_prompt %} |
|
|
{{- '<|start_header_id|>assistant<|end_header_id|> |
|
|
|
|
|
' }} |
|
|
{%- endif %} |