# Usage issue regarding Mistral

**URL:** <https://discuss.huggingface.co/t/usage-issue-regarding-mistral/75509>\
**Category:** 🤗Transformers\
**Created:** [March 1, 2024, 5:38pm UTC](https://discuss.huggingface.co/t/usage-issue-regarding-mistral/75509 "2024-03-01T17:38:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yananchen](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/yananchen/32/37864_2.png) [@yananchen](https://discuss.huggingface.co/u/yananchen)\
**Post date:** [March 1, 2024, 5:38pm UTC](https://discuss.huggingface.co/t/usage-issue-regarding-mistral/75509/1 "2024-03-01T17:38:21Z")

</div>

```auto
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import pipeline

MODEL = "mistralai/Mistral-7B-Instruct-v0.2"
tokenizer = AutoTokenizer.from_pretrained(MODEL, cache_dir='/home/yanan/downloads')
tokenizer.default_chat_template

```

hi there, after i execute the code above, here is the jinja template:

> {% if messages[0][‘role’] == ‘system’ %}{% set loop\_messages = messages[1:] %}{% set system\_message = messages[0][‘content’] %}{% elif false == true and not ‘\<\>’  
> in messages[0][‘content’] %}{% set loop\_messages = messages %}{% set system\_message = 'You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially  
> unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don\'t know the answer to a question, please don\‘t share false information.’ %}{% else %}{% set loop\_messages = messages %}{% set system\_message = false %}{% endif %}{% for message  
> in loop\_messages %}{% if (message[‘role’] == ‘user’) != (loop.index0 % 2 == 0) %}{{ raise\_exception(‘Conversation roles must alternate user/assistant/user/assistant/…’) }}{% endif %}{% if loop.index0 == 0 and system\_message != false %}{% set content = ‘\<\>\n’ + system\_message + ‘\n\<\>\n\n’ + message[‘content’] %}{% else %}{% set content  
> = message[‘content’] %}{% endif %}{% if message[‘role’] == ‘user’ %}{{ bos\_token + ‘[INST] ’ + content.strip() + ’ [/INST]’ }}{% elif message[‘role’] == ‘system’ %}{{ ‘\<\>\n’ + content.strip() + ‘\n\<\>\n\n’ }}{% elif message[‘role’] == ‘assistant’ %}{{ ’ ’ + content.strip() + ’ ’ + eos\_token }}{% endif %}{% endfor %}"

we can find that the system role is accepted here.

however, when i pass my prompt message:

```auto
messages = [
    {'role': 'system', 'content':'you are a food recommender system'},
    {"role": "user", "content": "What is your favourite condiment?"},
    {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
    {"role": "user", "content": "Do you have mayonnaise recipes?"}
]

```

into tokenizer, as  
`tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)`

it raises error:` TemplateError: Conversation roles must alternate user/assistant/user/assistant/...`

may I ask the reason for this ?
