Update chat_template.jinja
Browse files- chat_template.jinja +154 -12
chat_template.jinja
CHANGED
|
@@ -1,44 +1,186 @@
|
|
| 1 |
-
{
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
{%- if messages[0]['role'] == 'system' -%}
|
| 7 |
{%- set system_message = messages[0]['content'] -%}
|
| 8 |
-
{%- set
|
|
|
|
| 9 |
{%- else -%}
|
| 10 |
-
{%- set system_message = 'You are Helion,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
{%- endif -%}
|
| 12 |
|
| 13 |
{{- bos_token -}}
|
| 14 |
|
| 15 |
-
{%- if system_message -%}
|
| 16 |
<|system|>
|
| 17 |
-
{{ system_message }}
|
| 18 |
</s>
|
| 19 |
{%- endif -%}
|
| 20 |
|
| 21 |
-
{%- for message in
|
|
|
|
|
|
|
| 22 |
{%- if message['role'] == 'user' -%}
|
| 23 |
<|user|>
|
|
|
|
| 24 |
{%- if message.get('images') -%}
|
| 25 |
-
{%-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
<image>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
{%- endfor -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
{%- endif -%}
|
| 29 |
-
{{ message['content'] }}
|
| 30 |
</s>
|
|
|
|
| 31 |
{%- elif message['role'] == 'assistant' -%}
|
| 32 |
<|assistant|>
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
</s>
|
|
|
|
| 35 |
{%- elif message['role'] == 'tool' -%}
|
| 36 |
<|tool|>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
{{ message['content'] }}
|
| 38 |
</s>
|
| 39 |
{%- endif -%}
|
|
|
|
| 40 |
{%- endfor -%}
|
| 41 |
|
| 42 |
{%- if add_generation_prompt -%}
|
|
|
|
| 43 |
<|assistant|>
|
|
|
|
|
|
|
|
|
|
| 44 |
{%- endif -%}
|
|
|
|
| 1 |
+
{%- set ns = namespace(
|
| 2 |
+
has_system=false,
|
| 3 |
+
has_images=false,
|
| 4 |
+
has_tools=false,
|
| 5 |
+
message_count=0,
|
| 6 |
+
image_count=0,
|
| 7 |
+
tool_call_count=0
|
| 8 |
+
) -%}
|
| 9 |
|
| 10 |
{%- if messages[0]['role'] == 'system' -%}
|
| 11 |
{%- set system_message = messages[0]['content'] -%}
|
| 12 |
+
{%- set loop_messages = messages[1:] -%}
|
| 13 |
+
{%- set ns.has_system = true -%}
|
| 14 |
{%- else -%}
|
| 15 |
+
{%- set system_message = 'You are Helion, an advanced AI assistant with the following capabilities:
|
| 16 |
+
|
| 17 |
+
1. Vision Understanding: You can analyze images, charts, diagrams, documents, and screenshots. Use the <image> token to reference visual inputs.
|
| 18 |
+
|
| 19 |
+
2. Tool Use: You can call functions and use tools by responding with valid JSON in the format: {"tool": "tool_name", "parameters": {...}}
|
| 20 |
+
|
| 21 |
+
3. Long Context: You can process and remember up to 200,000 tokens of conversation history.
|
| 22 |
+
|
| 23 |
+
4. Reasoning: You excel at step-by-step logical reasoning, mathematical problem-solving, and code generation.
|
| 24 |
+
|
| 25 |
+
5. Multilingual: You can communicate in 12+ languages with strong performance.
|
| 26 |
+
|
| 27 |
+
Guidelines:
|
| 28 |
+
- Always be helpful, respectful, and honest
|
| 29 |
+
- Provide accurate, well-reasoned responses
|
| 30 |
+
- Cite sources when referencing external information
|
| 31 |
+
- Admit uncertainty when appropriate
|
| 32 |
+
- Refuse harmful or inappropriate requests
|
| 33 |
+
- Use tools when they would be helpful
|
| 34 |
+
- Break down complex problems into steps
|
| 35 |
+
- Consider multiple perspectives' -%}
|
| 36 |
+
{%- set loop_messages = messages -%}
|
| 37 |
{%- endif -%}
|
| 38 |
|
| 39 |
{{- bos_token -}}
|
| 40 |
|
| 41 |
+
{%- if system_message and system_message|length > 0 -%}
|
| 42 |
<|system|>
|
| 43 |
+
{{- system_message }}
|
| 44 |
</s>
|
| 45 |
{%- endif -%}
|
| 46 |
|
| 47 |
+
{%- for message in loop_messages -%}
|
| 48 |
+
{%- set ns.message_count = ns.message_count + 1 -%}
|
| 49 |
+
|
| 50 |
{%- if message['role'] == 'user' -%}
|
| 51 |
<|user|>
|
| 52 |
+
|
| 53 |
{%- if message.get('images') -%}
|
| 54 |
+
{%- set ns.has_images = true -%}
|
| 55 |
+
{%- if message['images'] is iterable and message['images'] is not string -%}
|
| 56 |
+
{%- for image in message['images'] -%}
|
| 57 |
+
{%- set ns.image_count = ns.image_count + 1 -%}
|
| 58 |
+
<image>
|
| 59 |
+
{%- endfor -%}
|
| 60 |
+
{%- else -%}
|
| 61 |
+
{%- set ns.image_count = ns.image_count + 1 -%}
|
| 62 |
<image>
|
| 63 |
+
{%- endif -%}
|
| 64 |
+
{%- endif -%}
|
| 65 |
+
|
| 66 |
+
{%- if message.get('documents') -%}
|
| 67 |
+
<documents>
|
| 68 |
+
{%- for doc in message['documents'] -%}
|
| 69 |
+
<document id="{{ doc.get('id', loop.index) }}" title="{{ doc.get('title', 'Document ' ~ loop.index) }}">
|
| 70 |
+
{{ doc.get('content', '') }}
|
| 71 |
+
</document>
|
| 72 |
{%- endfor -%}
|
| 73 |
+
</documents>
|
| 74 |
+
{%- endif -%}
|
| 75 |
+
|
| 76 |
+
{%- if message.get('context') -%}
|
| 77 |
+
<context>
|
| 78 |
+
{{ message['context'] }}
|
| 79 |
+
</context>
|
| 80 |
+
{%- endif -%}
|
| 81 |
+
|
| 82 |
+
{{- message['content'] -}}
|
| 83 |
+
|
| 84 |
+
{%- if message.get('constraints') -%}
|
| 85 |
+
|
| 86 |
+
<constraints>
|
| 87 |
+
{{ message['constraints'] }}
|
| 88 |
+
</constraints>
|
| 89 |
{%- endif -%}
|
|
|
|
| 90 |
</s>
|
| 91 |
+
|
| 92 |
{%- elif message['role'] == 'assistant' -%}
|
| 93 |
<|assistant|>
|
| 94 |
+
|
| 95 |
+
{%- if message.get('reasoning') -%}
|
| 96 |
+
<reasoning>
|
| 97 |
+
{{ message['reasoning'] }}
|
| 98 |
+
</reasoning>
|
| 99 |
+
|
| 100 |
+
{%- endif -%}
|
| 101 |
+
|
| 102 |
+
{%- if message.get('tool_calls') -%}
|
| 103 |
+
{%- set ns.has_tools = true -%}
|
| 104 |
+
{%- for tool_call in message['tool_calls'] -%}
|
| 105 |
+
{%- set ns.tool_call_count = ns.tool_call_count + 1 -%}
|
| 106 |
+
<tool_call id="{{ tool_call.get('id', 'call_' ~ ns.tool_call_count) }}">
|
| 107 |
+
{"tool": "{{ tool_call.get('name', tool_call.get('tool', 'unknown')) }}", "parameters": {{ tool_call.get('parameters', tool_call.get('arguments', '{}')) | tojson }}}
|
| 108 |
+
</tool_call>
|
| 109 |
+
{%- endfor -%}
|
| 110 |
+
|
| 111 |
+
{%- endif -%}
|
| 112 |
+
|
| 113 |
+
{{- message['content'] -}}
|
| 114 |
+
|
| 115 |
+
{%- if message.get('code_execution') -%}
|
| 116 |
+
|
| 117 |
+
<code_execution language="{{ message['code_execution'].get('language', 'python') }}">
|
| 118 |
+
{{ message['code_execution'].get('code', '') }}
|
| 119 |
+
</code_execution>
|
| 120 |
+
{%- endif -%}
|
| 121 |
+
|
| 122 |
+
{%- if message.get('citations') -%}
|
| 123 |
+
|
| 124 |
+
<citations>
|
| 125 |
+
{%- for citation in message['citations'] -%}
|
| 126 |
+
- [{{ loop.index }}] {{ citation.get('source', 'Unknown source') }}{% if citation.get('url') %}: {{ citation['url'] }}{% endif %}
|
| 127 |
+
{%- endfor -%}
|
| 128 |
+
</citations>
|
| 129 |
+
{%- endif -%}
|
| 130 |
</s>
|
| 131 |
+
|
| 132 |
{%- elif message['role'] == 'tool' -%}
|
| 133 |
<|tool|>
|
| 134 |
+
{%- if message.get('tool_call_id') -%}
|
| 135 |
+
<tool_result id="{{ message['tool_call_id'] }}">
|
| 136 |
+
{%- else -%}
|
| 137 |
+
<tool_result>
|
| 138 |
+
{%- endif -%}
|
| 139 |
+
|
| 140 |
+
{%- if message.get('result') -%}
|
| 141 |
+
{{ message['result'] | tojson if message['result'] is mapping else message['result'] }}
|
| 142 |
+
{%- else -%}
|
| 143 |
+
{{ message['content'] }}
|
| 144 |
+
{%- endif -%}
|
| 145 |
+
|
| 146 |
+
{%- if message.get('error') -%}
|
| 147 |
+
|
| 148 |
+
<error>
|
| 149 |
+
{{ message['error'] }}
|
| 150 |
+
</error>
|
| 151 |
+
{%- endif -%}
|
| 152 |
+
</tool_result>
|
| 153 |
+
</s>
|
| 154 |
+
|
| 155 |
+
{%- elif message['role'] == 'function' -%}
|
| 156 |
+
<|function|>
|
| 157 |
+
<function_response name="{{ message.get('name', 'unknown') }}">
|
| 158 |
+
{{ message['content'] }}
|
| 159 |
+
</function_response>
|
| 160 |
+
</s>
|
| 161 |
+
|
| 162 |
+
{%- elif message['role'] == 'thought' -%}
|
| 163 |
+
<|thought|>
|
| 164 |
+
{{ message['content'] }}
|
| 165 |
+
</s>
|
| 166 |
+
|
| 167 |
+
{%- elif message['role'] == 'observation' -%}
|
| 168 |
+
<|observation|>
|
| 169 |
+
{{ message['content'] }}
|
| 170 |
+
</s>
|
| 171 |
+
|
| 172 |
+
{%- else -%}
|
| 173 |
+
<|{{ message['role'] }}|>
|
| 174 |
{{ message['content'] }}
|
| 175 |
</s>
|
| 176 |
{%- endif -%}
|
| 177 |
+
|
| 178 |
{%- endfor -%}
|
| 179 |
|
| 180 |
{%- if add_generation_prompt -%}
|
| 181 |
+
{%- if ns.has_tools -%}
|
| 182 |
<|assistant|>
|
| 183 |
+
{%- else -%}
|
| 184 |
+
<|assistant|>
|
| 185 |
+
{%- endif -%}
|
| 186 |
{%- endif -%}
|