Update chat_template.jinja
Browse files- chat_template.jinja +27 -96
chat_template.jinja
CHANGED
|
@@ -1,26 +1,17 @@
|
|
| 1 |
{#- ======== Template Parameters ======== #}
|
| 2 |
{%- set add_generation_prompt = add_generation_prompt if add_generation_prompt is defined else true %}
|
| 3 |
{%- set default_system_prompt = default_system_prompt if default_system_prompt is defined else true %}
|
| 4 |
-
{%- set
|
| 5 |
-
{%- set think_render_option = think_render_option if think_render_option is defined else "lastthink" %}
|
| 6 |
|
| 7 |
{#- ======== System Block State ======== #}
|
| 8 |
{%- set sys_ns = namespace(is_first_block=true) -%}
|
| 9 |
|
| 10 |
-
{#- ======== Find last user message index ======== #}
|
| 11 |
-
{%- set last_user_idx = namespace(value=-1) -%}
|
| 12 |
-
{%- for message in messages -%}
|
| 13 |
-
{%- if message.role == 'user' -%}
|
| 14 |
-
{%- set last_user_idx.value = loop.index0 -%}
|
| 15 |
-
{%- endif -%}
|
| 16 |
-
{%- endfor -%}
|
| 17 |
-
|
| 18 |
{#- ======== System messages renderers ======== #}
|
| 19 |
{%- macro render_system_message(user_system_messages) %}
|
| 20 |
{%- if default_system_prompt %}
|
| 21 |
{%- if not sys_ns.is_first_block %}{{- "\n\n" }}{%- endif %}
|
| 22 |
{%- set sys_ns.is_first_block = false %}
|
| 23 |
-
{{- "## Provider System Prompt\n\nYou are Solar Open 100B, a large language model trained by Upstage AI
|
| 24 |
{%- endif -%}
|
| 25 |
{%- if user_system_messages %}
|
| 26 |
{%- if not sys_ns.is_first_block %}{{- "\n\n" }}{%- endif %}
|
|
@@ -33,54 +24,23 @@
|
|
| 33 |
{%- endif -%}
|
| 34 |
{%- endmacro %}
|
| 35 |
|
| 36 |
-
{
|
|
|
|
| 37 |
{%- if not sys_ns.is_first_block %}{{- "\n\n" }}{%- endif %}
|
| 38 |
{%- set sys_ns.is_first_block = false %}
|
| 39 |
-
{{- "##
|
| 40 |
-
{{- "
|
| 41 |
-
{{- "\n
|
| 42 |
-
{{- "
|
| 43 |
-
{%- for tool in tools %}
|
| 44 |
-
{{- "<|tool:begin|>" }}
|
| 45 |
-
{{- tool.function | tojson }}
|
| 46 |
-
{{- "<|tool:end|>" }}
|
| 47 |
-
{%- endfor %}
|
| 48 |
-
{{- "<|tools:end|>\n" }}
|
| 49 |
-
{{- "\n### Tool Call Format\n" }}
|
| 50 |
-
{{- "For each tool call, return a JSON object with the following structure, enclosed within <|tool_call:begin|> and <|tool_call:end|> tags: \n<|tool_call:begin|><tool-call-id><|tool_call:name|><tool-name><|tool_call:args|><args-json-object><|tool_call:end|>\n" }}
|
| 51 |
-
{{- "- The <tool-call-id> must be a randomly generated string consisting of 10 lowercase letters (a-z) and/or digits (0-9) (e.g., a1b2c3d4e5)\n" }}
|
| 52 |
-
{{- "\n### Tool Response Format\n" }}
|
| 53 |
-
{{- "Each tool is responded by `tool` with the following structure:\n<|tool_response:id|><tool-call-id><|tool_response:name|><tool-name><|tool_response:result|><results><|tool_response:end|>\n" }}
|
| 54 |
-
{{- "- Ensure the <tool-call-id> matches the corresponding tool call" -}}
|
| 55 |
{%- endmacro %}
|
| 56 |
|
| 57 |
-
{%- macro
|
| 58 |
{%- if not sys_ns.is_first_block %}{{- "\n\n" }}{%- endif %}
|
| 59 |
{%- set sys_ns.is_first_block = false %}
|
| 60 |
-
{{- "##
|
| 61 |
-
{
|
| 62 |
-
|
| 63 |
-
{
|
| 64 |
-
{%- endmacro %}
|
| 65 |
-
|
| 66 |
-
{%- macro get_tool_name(messages, tool_call_id) %}
|
| 67 |
-
{%- for msg in messages -%}
|
| 68 |
-
{%- if msg.role == 'assistant' and msg.tool_calls -%}
|
| 69 |
-
{%- for tool_call in msg.tool_calls -%}
|
| 70 |
-
{%- if tool_call.id == tool_call_id -%}
|
| 71 |
-
{{- tool_call.function.name }}
|
| 72 |
-
{%- endif -%}
|
| 73 |
-
{%- endfor -%}
|
| 74 |
-
{%- endif -%}
|
| 75 |
-
{%- endfor -%}
|
| 76 |
-
{%- endmacro %}
|
| 77 |
-
|
| 78 |
-
{%- macro render_tool_arguments(tool_arguments) %}
|
| 79 |
-
{%- if tool_arguments is mapping -%}
|
| 80 |
-
{{- tool_arguments | tojson }}
|
| 81 |
-
{%- else -%}
|
| 82 |
-
{{- tool_arguments }}
|
| 83 |
-
{%- endif -%}
|
| 84 |
{%- endmacro %}
|
| 85 |
|
| 86 |
{#- ======== Render system message ======== #}
|
|
@@ -91,15 +51,15 @@
|
|
| 91 |
{%- endif -%}
|
| 92 |
{%- endfor -%}
|
| 93 |
|
| 94 |
-
{%- if ns.system_messages or default_system_prompt or
|
| 95 |
{{- "<|begin|>system<|content|>" }}
|
| 96 |
{{- render_system_message(ns.system_messages) }}
|
|
|
|
|
|
|
|
|
|
| 97 |
{%- if tools -%}
|
| 98 |
{{- render_tool_instruction(tools) }}
|
| 99 |
{%- endif %}
|
| 100 |
-
{%- if response_format -%}
|
| 101 |
-
{{- render_json_response_format_instruction(response_format) }}
|
| 102 |
-
{%- endif %}
|
| 103 |
{{- "<|end|>" }}
|
| 104 |
{%- endif -%}
|
| 105 |
|
|
@@ -107,50 +67,21 @@
|
|
| 107 |
{%- for message in messages -%}
|
| 108 |
{%- if message.role == 'user' -%}
|
| 109 |
{{- "<|begin|>user<|content|>" + message.content + "<|end|>" }}
|
| 110 |
-
{%- elif message.role == 'tool' -%}
|
| 111 |
-
{%- set prev_is_tool = loop.index0 > 0 and messages[loop.index0 - 1].role == 'tool' -%}
|
| 112 |
-
{%- set next_is_tool = loop.index0 < (messages | length - 1) and messages[loop.index0 + 1].role == 'tool' -%}
|
| 113 |
-
{%- if not prev_is_tool -%}
|
| 114 |
-
{{- "<|begin|>tool<|tool_response|>" }}
|
| 115 |
-
{%- endif -%}
|
| 116 |
-
{{- "<|tool_response:begin|>" + message.tool_call_id + "<|tool_response:name|>" }}
|
| 117 |
-
{{- get_tool_name(messages, message.tool_call_id) }}
|
| 118 |
-
{{- "<|tool_response:result|>" }}
|
| 119 |
-
{{- message.content }}
|
| 120 |
-
{{- "<|tool_response:end|>" }}
|
| 121 |
-
{%- if not next_is_tool -%}
|
| 122 |
-
{{- "<|end|>" }}
|
| 123 |
-
{%- endif -%}
|
| 124 |
{%- elif message.role == 'assistant' -%}
|
| 125 |
-
{
|
| 126 |
-
|
| 127 |
-
{%- if message.reasoning -%}
|
| 128 |
-
{{- "<|begin|>assistant<|think|>" + message.reasoning + "<|end|>" }}
|
| 129 |
-
{%- endif -%}
|
| 130 |
-
{%- elif think_render_option == "lastthink" -%}
|
| 131 |
-
{%- if message.reasoning and loop.index0 > last_user_idx.value -%}
|
| 132 |
-
{{- "<|begin|>assistant<|think|>" + message.reasoning + "<|end|>" }}
|
| 133 |
-
{%- endif -%}
|
| 134 |
-
{%- endif -%}
|
| 135 |
-
|
| 136 |
-
{#- ======== Assistant Messages ======== #}
|
| 137 |
-
{%- if message.tool_calls -%}
|
| 138 |
-
{{- "<|begin|>assistant<|tool_calls|>" }}
|
| 139 |
-
{%- for tool_call in message.tool_calls -%}
|
| 140 |
-
{{- "<|tool_call:begin|>" + tool_call.id +"<|tool_call:name|>" + tool_call.function.name + "<|tool_call:args|>" }}
|
| 141 |
-
{{- render_tool_arguments(tool_call.function.arguments) }}
|
| 142 |
-
{{- "<|tool_call:end|>" }}
|
| 143 |
-
{%- endfor -%}
|
| 144 |
-
{{- "<|calls|>" }}
|
| 145 |
{%- else -%}
|
| 146 |
-
|
| 147 |
{%- endif -%}
|
| 148 |
{%- endif -%}
|
| 149 |
{%- endfor -%}
|
| 150 |
|
|
|
|
| 151 |
{%- if add_generation_prompt -%}
|
| 152 |
-
{%- if reasoning_effort in ["low", "minimal"] -%}
|
| 153 |
-
{{- "<|begin|>assistant<|think|><|end|>" }}
|
| 154 |
-
{%- endif -%}
|
| 155 |
{{- "<|begin|>assistant" }}
|
| 156 |
-
{%-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{#- ======== Template Parameters ======== #}
|
| 2 |
{%- set add_generation_prompt = add_generation_prompt if add_generation_prompt is defined else true %}
|
| 3 |
{%- set default_system_prompt = default_system_prompt if default_system_prompt is defined else true %}
|
| 4 |
+
{%- set enable_thinking = enable_thinking if enable_thinking is defined else true %}
|
|
|
|
| 5 |
|
| 6 |
{#- ======== System Block State ======== #}
|
| 7 |
{%- set sys_ns = namespace(is_first_block=true) -%}
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
{#- ======== System messages renderers ======== #}
|
| 10 |
{%- macro render_system_message(user_system_messages) %}
|
| 11 |
{%- if default_system_prompt %}
|
| 12 |
{%- if not sys_ns.is_first_block %}{{- "\n\n" }}{%- endif %}
|
| 13 |
{%- set sys_ns.is_first_block = false %}
|
| 14 |
+
{{- "## Provider System Prompt\n\nYou are Solar Open 100B, a large language model trained by Upstage AI. Your knowledge cutoff is 2025-07. The current date is 2026-01-07." }}
|
| 15 |
{%- endif -%}
|
| 16 |
{%- if user_system_messages %}
|
| 17 |
{%- if not sys_ns.is_first_block %}{{- "\n\n" }}{%- endif %}
|
|
|
|
| 24 |
{%- endif -%}
|
| 25 |
{%- endmacro %}
|
| 26 |
|
| 27 |
+
{#- Hardcoded Minimal Thinking Instruction with Math Focus #}
|
| 28 |
+
{%- macro render_thinking_instruction() %}
|
| 29 |
{%- if not sys_ns.is_first_block %}{{- "\n\n" }}{%- endif %}
|
| 30 |
{%- set sys_ns.is_first_block = false %}
|
| 31 |
+
{{- "## Thinking Guidelines\n" }}
|
| 32 |
+
{{- "You must think before answering. Keep thoughts extremely brief and focused." }}
|
| 33 |
+
{{- "\n- Verify the core intent and jump to the answer." }}
|
| 34 |
+
{{- "\n- For math problems: Break them down into simple, discrete steps. Use fractions to maintain precision where possible, and simplify expressions to their lowest terms." }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
{%- endmacro %}
|
| 36 |
|
| 37 |
+
{%- macro render_tool_instruction(tools) %}
|
| 38 |
{%- if not sys_ns.is_first_block %}{{- "\n\n" }}{%- endif %}
|
| 39 |
{%- set sys_ns.is_first_block = false %}
|
| 40 |
+
{{- "## Tools Instruction\nUse the following tools if needed: " }}
|
| 41 |
+
{%- for tool in tools %}
|
| 42 |
+
{{- tool.function | tojson }}
|
| 43 |
+
{%- endfor %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
{%- endmacro %}
|
| 45 |
|
| 46 |
{#- ======== Render system message ======== #}
|
|
|
|
| 51 |
{%- endif -%}
|
| 52 |
{%- endfor -%}
|
| 53 |
|
| 54 |
+
{%- if ns.system_messages or default_system_prompt or enable_thinking -%}
|
| 55 |
{{- "<|begin|>system<|content|>" }}
|
| 56 |
{{- render_system_message(ns.system_messages) }}
|
| 57 |
+
{%- if enable_thinking -%}
|
| 58 |
+
{{- render_thinking_instruction() }}
|
| 59 |
+
{%- endif %}
|
| 60 |
{%- if tools -%}
|
| 61 |
{{- render_tool_instruction(tools) }}
|
| 62 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
| 63 |
{{- "<|end|>" }}
|
| 64 |
{%- endif -%}
|
| 65 |
|
|
|
|
| 67 |
{%- for message in messages -%}
|
| 68 |
{%- if message.role == 'user' -%}
|
| 69 |
{{- "<|begin|>user<|content|>" + message.content + "<|end|>" }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
{%- elif message.role == 'assistant' -%}
|
| 71 |
+
{%- if message.reasoning -%}
|
| 72 |
+
{{- "<|begin|>assistant<|think|>" + message.reasoning + "<|end|><|begin|>assistant<|content|>" + message.content + "<|end|>" }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
{%- else -%}
|
| 74 |
+
{{- "<|begin|>assistant<|content|>" + message.content + "<|end|>" }}
|
| 75 |
{%- endif -%}
|
| 76 |
{%- endif -%}
|
| 77 |
{%- endfor -%}
|
| 78 |
|
| 79 |
+
{#- ======== Generation Prompt Logic ======== #}
|
| 80 |
{%- if add_generation_prompt -%}
|
|
|
|
|
|
|
|
|
|
| 81 |
{{- "<|begin|>assistant" }}
|
| 82 |
+
{%- if enable_thinking -%}
|
| 83 |
+
{{- "<|think|>" }}
|
| 84 |
+
{%- else -%}
|
| 85 |
+
{{- "<|content|>" }}
|
| 86 |
+
{%- endif -%}
|
| 87 |
+
{%- endif -%}
|