Skip to content

Instantly share code, notes, and snippets.

@craftgear
Created March 16, 2026 04:17
Show Gist options
  • Select an option

  • Save craftgear/27b9036514b577f85b14eb15f588b6b2 to your computer and use it in GitHub Desktop.

Select an option

Save craftgear/27b9036514b577f85b14eb15f588b6b2 to your computer and use it in GitHub Desktop.
Qwen3.5 jinja template to run superpowers on opencode
{#
Qwen3.5-compatible relaxed chat template
Purpose:
- allow multiple system messages
- treat developer messages like system messages
- merge all leading/interleaved system/developer messages into one system block
- avoid "System message must be at the beginning"
#}
{%- set ns = namespace(
system_text='',
messages=[],
tools=tools if tools is defined else none
) -%}
{# Collect all system/developer content into one block #}
{%- for message in messages -%}
{%- if message.role == 'system' or message.role == 'developer' -%}
{%- if message.content is string -%}
{%- if ns.system_text != '' -%}
{%- set ns.system_text = ns.system_text + '\n\n' + message.content -%}
{%- else -%}
{%- set ns.system_text = message.content -%}
{%- endif -%}
{%- elif message.content is iterable -%}
{%- set content_text = '' -%}
{%- for part in message.content -%}
{%- if part is mapping and part.type == 'text' -%}
{%- if content_text != '' -%}
{%- set content_text = content_text + '\n' + part.text -%}
{%- else -%}
{%- set content_text = part.text -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- if content_text != '' -%}
{%- if ns.system_text != '' -%}
{%- set ns.system_text = ns.system_text + '\n\n' + content_text -%}
{%- else -%}
{%- set ns.system_text = content_text -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}
{%- else -%}
{%- set ns.messages = ns.messages + [message] -%}
{%- endif -%}
{%- endfor -%}
{# Emit BOS #}
{{- bos_token if bos_token is defined else '' -}}
{# Emit merged system block first #}
{%- if ns.system_text != '' -%}
<|im_start|>system
{{ ns.system_text }}<|im_end|>
{%- endif -%}
{# Optional tool schema block: include inside system if your client expects it there #}
{%- if ns.tools is not none and ns.tools|length > 0 -%}
<|im_start|>system
You have access to the following tools:
{%- for tool in ns.tools %}
{{ tool | tojson }}
{%- if not loop.last %}
{%- endif %}
{%- endfor %}
When calling a tool, respond with valid JSON only.<|im_end|>
{%- endif -%}
{# Emit remaining conversation #}
{%- for message in ns.messages -%}
{%- if message.role == 'user' -%}
<|im_start|>user
{%- if message.content is string -%}
{{ message.content }}
{%- else -%}
{%- for part in message.content -%}
{%- if part is mapping and part.type == 'text' -%}
{{ part.text }}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
<|im_end|>
{%- elif message.role == 'assistant' -%}
<|im_start|>assistant
{%- if message.content is string -%}
{{ message.content }}
{%- elif message.content is not none -%}
{%- for part in message.content -%}
{%- if part is mapping and part.type == 'text' -%}
{{ part.text }}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
<|im_end|>
{%- elif message.role == 'tool' -%}
<|im_start|>tool
{%- if message.content is string -%}
{{ message.content }}
{%- else -%}
{{ message.content | tojson }}
{%- endif -%}
<|im_end|>
{%- endif -%}
{%- endfor -%}
{# Generation prompt #}
<|im_start|>assistant
@craftgear
Copy link
Copy Markdown
Author

save the file and add these arguments when you run llama.server

  --jinja \
  --chat-template-file ~/templates/qwen35-relaxed.jinja

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment