| |
| {{ bos_token }} |
| |
| {%- if messages[0]['role'] == 'system' -%} |
| {%- if messages[0]['content'] is string -%} |
| {%- set system_message = messages[0]['content'] -%} |
| {%- else -%} |
| {%- set system_message = messages[0]['content'][0]['text'] -%} |
| {%- endif -%} |
| {%- set loop_messages = messages[1:] -%} |
| {%- else -%} |
| {%- set system_message = "You are a helpful assistant Zero-Gemma made by ZeroAgency company from Russia. You must be helpful, harmless, and honest." -%} |
| {%- set loop_messages = messages -%} |
| {%- endif -%} |
| |
| {%- if enable_thinking is defined and enable_thinking is true -%} |
| {%- set system_message = system_message + "\nFirst, think through the reasoning internally, then present the reasoning within <think>...</think>. After thinking, clearly state a response that addresses the user's request and aligns with their preferences, not just providing a direct answer." -%} |
| {%- endif -%} |
| |
| {%- set system_message = system_message + '\n\n' -%} |
| |
| {%- if not tools is defined -%} |
| {%- set tools = none -%} |
| {%- endif -%} |
| |
| |
| |
| {{ '<start_of_turn>system\n' -}} |
| {{ system_message }} |
| |
| {%- if tools is not none -%} |
| {{- "Tools (functions) are available. If you decide to invoke one or more of the tools, you must respond with a python list of the function calls.\n" -}} |
| {{- "Example Format: [func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)] \n" -}} |
| {{- "Do not use variables. DO NOT USE MARKDOWN SYNTAX. You SHOULD NOT include any other text in the response if you call a function. If none of the functions can be used, point it out. If you lack the parameters required by the function, also point it out.\n" -}} |
| {{- "Here is a list of functions in JSON format that you can invoke.\n" -}} |
| {{- tools | tojson(indent=4) -}} |
| {{- "\n\n" -}} |
| {%- endif -%} |
| {{ '<end_of_turn>\n' }} |
| |
| |
| {%- for message in loop_messages if message['role'] != 'system' -%} |
| |
| {%- if (message['role'] == 'assistant') -%} |
| {%- set role = "model" -%} |
| {%- elif (message['role'] == 'tool') -%} |
| {%- set role = "user" -%} |
| {%- else -%} |
| {%- set role = message['role'] -%} |
| {%- endif -%} |
| |
| {{ '<start_of_turn>' + role + '\n' -}} |
| |
| |
| {%- if 'tool_calls' in message -%} |
| {%- if message['content'] is string -%} |
| {%- set content = message['content'] -%} |
| |
| {{- content | trim -}} |
| |
| |
| {%- endif -%} |
| |
| {{- '[' -}} |
| |
| {%- for tool_call in message.tool_calls -%} |
| |
| {%- if tool_call.function is defined -%} |
| {%- set tool_call = tool_call.function -%} |
| {%- endif -%} |
| {{- tool_call.name + '(' -}} |
| |
| |
| |
| {%- if tool_call.arguments is iterable and tool_call.arguments is mapping -%} |
| {%- set first = true -%} |
| {%- for key, val in tool_call.arguments.items() -%} |
| {%- if not first %}, {% endif -%} |
| {{ key }}={{ val | tojson }} |
| {%- set first = false -%} |
| {%- endfor -%} |
| |
| {%- elif tool_call.arguments is iterable -%} |
| {{- tool_call.arguments | map('tojson') | join(', ') -}} |
| |
| {%- else -%} |
| {{- tool_call.arguments | tojson -}} |
| |
| {%- endif -%} |
| {{- ')' -}} |
| |
| {%- if not loop.last -%}{{- "," -}}{%- endif -%} |
| {%- endfor -%} |
| |
| {{- ']' -}} |
| {%- endif -%} |
| |
| |
| {%- if (message['role'] == 'tool') -%} |
| {{- '<tool_response>\n' -}} |
| {%- endif -%} |
| |
| |
| {%- if not 'tool_calls' in message and message['content'] -%} |
| {%- if message['content'] is string -%} |
| {%- set content = message['content'] -%} |
| |
| |
| |
| {{- content | trim -}} |
| {%- elif message['content'] is iterable -%} |
| {%- for item in message['content'] -%} |
| {%- if item['type'] == 'image' -%} |
| {{ '<start_of_image>' }} |
| {%- elif item['type'] == 'text' -%} |
| {%- set content = item['text'] -%} |
| |
| |
| |
| {{ content | trim }} |
| {%- endif -%} |
| {%- endfor -%} |
| {%- else -%} |
| {{ raise_exception("Invalid content type:"+ message|tojson) }} |
| {%- endif -%} |
| {%- endif -%} |
| |
| |
| {%- if (message['role'] == 'tool') -%} |
| {{ '</tool_response>' -}} |
| {%- endif -%} |
| |
| |
| {{ '<end_of_turn>\n' }} |
| {%- endfor -%} |
| |
| |
| {%- if add_generation_prompt -%} |
| {{'<start_of_turn>model\n'}} |
| {%- if enable_thinking is defined and enable_thinking is true -%} |
| {{- '<think>' -}} |
| {%- endif %} |
| {%- endif -%} |