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