Upload chat_template.jinja
Browse files- chat_template.jinja +11 -33
chat_template.jinja
CHANGED
|
@@ -10,24 +10,6 @@
|
|
| 10 |
} %}
|
| 11 |
{%- set end_of_turn = '[|endofturn|]\n' %}
|
| 12 |
|
| 13 |
-
|
| 14 |
-
{%- macro available_tools(tools) %}
|
| 15 |
-
{{- "# Available Tools" }}
|
| 16 |
-
{{- "\nYou can use none, one, or multiple of the following tools by calling them as functions to help with the user’s query." }}
|
| 17 |
-
{{- "\nHere are the tools available to you in JSON format within <tool> and </tool> tags:\n" }}
|
| 18 |
-
{%- for tool in tools %}
|
| 19 |
-
{{- "<tool>" }}
|
| 20 |
-
{{- tool | tojson }}
|
| 21 |
-
{{- "</tool>\n" }}
|
| 22 |
-
{%- endfor %}
|
| 23 |
-
|
| 24 |
-
{{- "\nFor each function call you want to make, return a JSON object with function name and arguments within <tool_call> and </tool_call> tags, like:" }}
|
| 25 |
-
{{- "\n<tool_call>{\"name\": function_1_name, \"arguments\": {argument_1_name: argument_1_value, argument_2_name: argument_2_value}}</tool_call>" }}
|
| 26 |
-
{{- "\n<tool_call>{\"name\": function_2_name, \"arguments\": {...}}</tool_call>\n..." }}
|
| 27 |
-
{{- "\nNote that if no argument name is specified for a tool, you can just print the argument value directly, without the argument name or JSON formatting." }}
|
| 28 |
-
{%- endmacro %}
|
| 29 |
-
|
| 30 |
-
|
| 31 |
{%- set ns = namespace(last_query_index = messages|length - 1) %}
|
| 32 |
{%- for message in messages %}
|
| 33 |
{%- if message.role == "user" and message.content is string %}
|
|
@@ -38,32 +20,28 @@
|
|
| 38 |
{%- for i in range(messages | length) %}
|
| 39 |
{%- set msg = messages[i] %}
|
| 40 |
{%- set role = msg.role %}
|
| 41 |
-
{
|
| 42 |
{{- raise_exception('Unknown role: ' ~ role) }}
|
| 43 |
{%- endif %}
|
| 44 |
|
|
|
|
| 45 |
{%- if i == 0 %}
|
| 46 |
{%- if role == 'system' %}
|
| 47 |
{{- role_indicators['system'] }}
|
| 48 |
{{- msg.content }}
|
| 49 |
-
{%- if tools is defined and tools %}
|
| 50 |
-
{{- "\n\n" }}{{- available_tools(tools) }}
|
| 51 |
-
{%- endif %}
|
| 52 |
-
{{- end_of_turn -}}
|
| 53 |
-
{%- continue %}
|
| 54 |
-
{%- elif tools is defined and tools %}
|
| 55 |
-
{{- role_indicators['system'] }}
|
| 56 |
-
{{- available_tools(tools) }}
|
| 57 |
{{- end_of_turn -}}
|
|
|
|
| 58 |
{%- endif %}
|
| 59 |
{%- endif %}
|
| 60 |
|
| 61 |
{%- if role == 'assistant' %}
|
| 62 |
{{- role_indicators['assistant'] }}
|
| 63 |
|
| 64 |
-
{%- if msg.content %}
|
| 65 |
{%- if "</think>" in msg.content %}
|
| 66 |
-
{%- set content = msg.content.split('</think>')
|
|
|
|
|
|
|
| 67 |
{%- set reasoning_content = msg.content.split('</think>')[0].strip() %}
|
| 68 |
{%- if reasoning_content.startswith("<think>") %}
|
| 69 |
{%- set reasoning_content = reasoning_content[9:].strip() %}
|
|
@@ -105,7 +83,7 @@
|
|
| 105 |
{{- raise_exception('arguments or parameters are mandatory: ' ~ tool_call) }}
|
| 106 |
{%- endif %}
|
| 107 |
|
| 108 |
-
{{- "<tool_call>" }}{"name": "{{- tool_call.name }}", "arguments": {{ arguments | tojson }}}{{- "</tool_call>" }}
|
| 109 |
|
| 110 |
{%- if not loop.last %}
|
| 111 |
{{- "\n" }}
|
|
@@ -119,8 +97,8 @@
|
|
| 119 |
{%- if i == 0 or messages[i - 1].role != "tool" %}
|
| 120 |
{{- role_indicators['tool'] }}
|
| 121 |
{%- endif %}
|
| 122 |
-
{%- if msg.content is defined %}
|
| 123 |
-
{{- "<tool_result>" }}{"result": {{ msg.content | tojson }}}{{- "</tool_result>" }}
|
| 124 |
{%- endif %}
|
| 125 |
{%- if loop.last or messages[i + 1].role != "tool" %}
|
| 126 |
{{- end_of_turn -}}
|
|
@@ -128,7 +106,7 @@
|
|
| 128 |
{{- "\n" }}
|
| 129 |
{%- endif %}
|
| 130 |
|
| 131 |
-
{%-
|
| 132 |
{{- role_indicators[role] }}
|
| 133 |
{{- msg.content }}
|
| 134 |
{{- end_of_turn -}}
|
|
|
|
| 10 |
} %}
|
| 11 |
{%- set end_of_turn = '[|endofturn|]\n' %}
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
{%- set ns = namespace(last_query_index = messages|length - 1) %}
|
| 14 |
{%- for message in messages %}
|
| 15 |
{%- if message.role == "user" and message.content is string %}
|
|
|
|
| 20 |
{%- for i in range(messages | length) %}
|
| 21 |
{%- set msg = messages[i] %}
|
| 22 |
{%- set role = msg.role %}
|
| 23 |
+
{%- if role not in role_indicators %}
|
| 24 |
{{- raise_exception('Unknown role: ' ~ role) }}
|
| 25 |
{%- endif %}
|
| 26 |
|
| 27 |
+
{%- set skip_ns = namespace(skip_standard = false) %}
|
| 28 |
{%- if i == 0 %}
|
| 29 |
{%- if role == 'system' %}
|
| 30 |
{{- role_indicators['system'] }}
|
| 31 |
{{- msg.content }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
{{- end_of_turn -}}
|
| 33 |
+
{%- set skip_ns.skip_standard = true %}
|
| 34 |
{%- endif %}
|
| 35 |
{%- endif %}
|
| 36 |
|
| 37 |
{%- if role == 'assistant' %}
|
| 38 |
{{- role_indicators['assistant'] }}
|
| 39 |
|
| 40 |
+
{%- if msg.content %}
|
| 41 |
{%- if "</think>" in msg.content %}
|
| 42 |
+
{%- set content = msg.content.split('</think>') %}
|
| 43 |
+
{%- set content = content[-1] %}
|
| 44 |
+
{%- set content = content.strip() %}
|
| 45 |
{%- set reasoning_content = msg.content.split('</think>')[0].strip() %}
|
| 46 |
{%- if reasoning_content.startswith("<think>") %}
|
| 47 |
{%- set reasoning_content = reasoning_content[9:].strip() %}
|
|
|
|
| 83 |
{{- raise_exception('arguments or parameters are mandatory: ' ~ tool_call) }}
|
| 84 |
{%- endif %}
|
| 85 |
|
| 86 |
+
{{- "<tool_call>" }}{"name": "{{- tool_call.name }}", "arguments": {{ arguments | tojson(ensure_ascii=False) }}}{{- "</tool_call>" }}
|
| 87 |
|
| 88 |
{%- if not loop.last %}
|
| 89 |
{{- "\n" }}
|
|
|
|
| 97 |
{%- if i == 0 or messages[i - 1].role != "tool" %}
|
| 98 |
{{- role_indicators['tool'] }}
|
| 99 |
{%- endif %}
|
| 100 |
+
{%- if msg.content is defined %}
|
| 101 |
+
{{- "<tool_result>" }}{"result": {{ msg.content | tojson(ensure_ascii=False) }}}{{- "</tool_result>" }}
|
| 102 |
{%- endif %}
|
| 103 |
{%- if loop.last or messages[i + 1].role != "tool" %}
|
| 104 |
{{- end_of_turn -}}
|
|
|
|
| 106 |
{{- "\n" }}
|
| 107 |
{%- endif %}
|
| 108 |
|
| 109 |
+
{%- elif skip_ns.skip_standard == false %}
|
| 110 |
{{- role_indicators[role] }}
|
| 111 |
{{- msg.content }}
|
| 112 |
{{- end_of_turn -}}
|