Skip to content

Instantly share code, notes, and snippets.

{%- set image_count = namespace(value=0) %}
{%- set video_count = namespace(value=0) %}
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
{%- if content is string %}
{{- content }}
{%- elif content is iterable and content is not mapping %}
{%- for item in content %}
{%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
{%- if is_system_content %}
{{- raise_exception('System message cannot contain images.') }}
{%- set template_version = "qwen3.8-safe-v2" %}
{#- -------------------------------------------------------------------------
Whitespace contract: every tag opener in this file carries a leading minus,
so it strips the whitespace and newlines that precede it. All emitted text
comes from string literals, which makes the rendered prompt byte-exact and
free of incidental newlines. Comment tags need the minus just as much as
block tags do; a plain comment tag breaks the strip chain and leaks the
surrounding indentation into the prompt.
------------------------------------------------------------------------- -#}
{#- The message list has to exist before anything else can inspect it. -#}