Upload chat_template.jinja with huggingface_hub
Browse files- chat_template.jinja +45 -0
    	
        chat_template.jinja
    ADDED
    
    | @@ -0,0 +1,45 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
             | 
| 2 | 
            +
            {%- for message in messages %}
         | 
| 3 | 
            +
                {#-- Validate role is a stringified integer --#}
         | 
| 4 | 
            +
                {%- if not message['role'] is string or not message['role'].isdigit() %}
         | 
| 5 | 
            +
                    {{- raise_exception("The role must be an integer or a stringified integer (e.g. '0') designating the speaker id") }}
         | 
| 6 | 
            +
                {%- endif %}
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                {#-- Validate content is a list --#}
         | 
| 9 | 
            +
                {%- set content = message['content'] %}
         | 
| 10 | 
            +
                {%- if content is not iterable or content is string %}
         | 
| 11 | 
            +
                    {{- raise_exception("The content must be a list") }}
         | 
| 12 | 
            +
                {%- endif %}
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                {#-- Collect content types --#}
         | 
| 15 | 
            +
                {%- set content_types = content | map(attribute='type') | list %}
         | 
| 16 | 
            +
                {%- set is_last = loop.last %}
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                {#-- Last message validation --#}
         | 
| 19 | 
            +
                {%- if is_last %}
         | 
| 20 | 
            +
                    {%- if 'text' not in content_types %}
         | 
| 21 | 
            +
                        {{- raise_exception("The last message must include one item of type 'text'") }}
         | 
| 22 | 
            +
                    {%- elif (content_types | select('equalto', 'text') | list | length > 1) or (content_types | select('equalto', 'audio') | list | length > 1) %}
         | 
| 23 | 
            +
                        {{- raise_exception("At most two items are allowed in the last message: one 'text' and one 'audio'") }}
         | 
| 24 | 
            +
                    {%- endif %}
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                {#-- All other messages validation --#}
         | 
| 27 | 
            +
                {%- else %}
         | 
| 28 | 
            +
                    {%- if content_types | select('equalto', 'text') | list | length != 1
         | 
| 29 | 
            +
                          or content_types | select('equalto', 'audio') | list | length != 1 %}
         | 
| 30 | 
            +
                        {{- raise_exception("Each message (except the last) must contain exactly one 'text' and one 'audio' item") }}
         | 
| 31 | 
            +
                    {%- elif content_types | reject('in', ['text', 'audio']) | list | length > 0 %}
         | 
| 32 | 
            +
                        {{- raise_exception("Only 'text' and 'audio' types are allowed in content") }}
         | 
| 33 | 
            +
                    {%- endif %}
         | 
| 34 | 
            +
                {%- endif %}
         | 
| 35 | 
            +
            {%- endfor %}
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            {%- for message in messages %}
         | 
| 38 | 
            +
                {{- bos_token }}
         | 
| 39 | 
            +
                {{- '[' + message['role'] + ']' }}
         | 
| 40 | 
            +
                {{- message['content'][0]['text'] }}
         | 
| 41 | 
            +
                {{- eos_token }}
         | 
| 42 | 
            +
                {%- if message['content']|length > 1 %}
         | 
| 43 | 
            +
                    {{- '<|AUDIO|><|audio_eos|>' }}
         | 
| 44 | 
            +
                {%- endif %}
         | 
| 45 | 
            +
            {%- endfor %}
         | 
