{% macro render_extra_keys(json_dict, handled_keys) %} {%- if json_dict is mapping %} {%- for json_key in json_dict if json_key not in handled_keys %} {%- if json_dict[json_key] is mapping or (json_dict[json_key] is sequence and json_dict[json_key] is not string) %} {{- '\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | tojson | safe) ~ '' }} {%- else %} {{-'\n<' ~ json_key ~ '>' ~ (json_dict[json_key] | string) ~ '' }} {%- endif %} {%- endfor %} {%- endif %} {% endmacro %} {%- macro render_content(content) -%} {%- if content is none -%} {{- '' -}} {%- elif content is string -%} {{- content | string -}} {%- else -%} {%- set text_ns = namespace(val='') -%} {%- set counters = namespace(images=0, videos=0) -%} {%- for part in content -%} {%- if part['type'] == 'image' or part['type'] == 'image_url' or part['type'] == 'input_image' -%} {%- set counters.images = counters.images + 1 -%} {%- elif part['type'] == 'video' or part['type'] == 'video_url' or part['type'] == 'input_video' -%} {%- set counters.videos = counters.videos + 1 -%} {%- elif part['type'] == 'text' or part['type'] == 'input_text' -%} {%- set text_ns.val = text_ns.val + (part['text'] | default('', true)) -%} {%- endif -%} {%- endfor -%} {%- if '' in text_ns.val -%} {%- set counters.images = 0 -%} {%- endif -%} {%- if '