File size: 2,044 Bytes
41be407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

{%- set identifier = 'im' %}
{% for message in messages %}
    {% if add_system_prompt and loop.first and message['role'] != 'system' %}
        {{- '<|im_start|>system
You are VideoLLaMA3 created by Alibaba DAMO Academy, a helpful assistant to help people understand images and videos.<|im_end|>
' -}}
    {% endif %}
    {% if message['role'] == 'stream' %}
        {% set identifier = 'stream' %}
    {% else %}
        {% set identifier = 'im' %}
    {% endif %}
    {{- '<|' + identifier + '_start|>' + message['role'] + '
' -}}
    {% if message['content'] is string %}
        {{- message['content'] + '<|' + identifier + '_end|>
' -}}
    {% else %}
        {% for content in message['content'] %}
            {% if content is string %}
                {{- content -}}
            {% elif content['type'] == 'text' or 'text' in content %}
                {{- content['text'] -}}
            {% elif content['type'] == 'image' or 'image' in content %}
                {% if 'timestamp' in content %}
                    {{- 'Time ' + content['timestamp'] | round(1) | string + 's: ' -}}
                {% endif %}

                {{- '<image>
' -}}

            {% elif content['type'] == 'video' or 'video' in content %}
                {% for i in range(content['num_frames']) %}
                    {% if 'timestamps' in content %}
                        {{- 'Time ' + content['timestamps'][i] | round(1) | string + 's:' -}}
                    {% endif %}
                    {% if i < content['num_frames'] - 1 %}

                        {{- '<image>,' -}}

                    {% else %}

                        {{- '<image>
' -}}

                    {% endif %}
                {% endfor %}
            {% endif %}
        {% endfor %}
        {% if identifier == 'stream' %}
            {{- '<|' + identifier + '_end|>' -}}
        {% else %}
            {{- '<|' + identifier + '_end|>
' -}}
        {% endif %}
    {% endif %}
{% endfor %}
{% if add_generation_prompt %}
    {{- '<|im_start|>assistant
' -}}
{% endif %}