# Cannot use chat template functions because tokenizer.chat\_template is not set

**URL:** <https://discuss.huggingface.co/t/cannot-use-chat-template-functions-because-tokenizer-chat-template-is-not-set/137565>\
**Category:** Beginners\
**Created:** [January 27, 2025, 3:01pm UTC](https://discuss.huggingface.co/t/cannot-use-chat-template-functions-because-tokenizer-chat-template-is-not-set/137565 "2025-01-27T15:01:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unclocked](https://avatars.discourse-cdn.com/v4/letter/u/4da419/32.png) [@Unclocked](https://discuss.huggingface.co/u/Unclocked)\
**Post date:** [January 27, 2025, 3:01pm UTC](https://discuss.huggingface.co/t/cannot-use-chat-template-functions-because-tokenizer-chat-template-is-not-set/137565/1 "2025-01-27T15:01:32Z")

</div>

The following Python script using Dolphin3.0 works well:

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

model_name = "cognitivecomputations/Dolphin3.0-Llama3.2-3B"

chat = [
    {"role": "system", "content": "You are a philosopher"},
    {"role": "assistant", "content": "Hello, Eve!"},
    {"role": "user", "content": "Hello, Adam!"}
]
    
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)

response = pipe(chat, max_new_tokens=32)
print(response[0]['generated_text'][-1]['content'])

```

However if I change the model name to:  
`model_name = "ObsidianLite/Euryale-1.3-Small-7B"`  
I encounter an error at the line where pipe is called:

> ValueError: Cannot use chat template functions because tokenizer.chat\_template is not set and no template argument was passed! For information about writing templates and setting the tokenizer.chat\_template attribute, please see the documentation at [Chat Templates](https://huggingface.co/docs/transformers/main/en/chat_templating)

Can someone help me correct my script?

Thank you!

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [January 27, 2025, 4:01pm UTC](https://discuss.huggingface.co/t/cannot-use-chat-template-functions-because-tokenizer-chat-template-is-not-set/137565/2 "2025-01-27T16:01:45Z")

</div>

Aside from the solution, I think the problem is probably this…

> [@Chat\_template is not set & throwing error](https://discuss.huggingface.co/t/chat-template-is-not-set-throwing-error/104095):
>
> When I am running the sample code from [here](https://huggingface.co/docs/transformers/v4.44.2/en/chat_templating#is-there-an-automated-pipeline-for-chat): tokenizer = AutoTokenizer.from\_pretrained("facebook/blenderbot-400M-distill") chat = [{"role": "user", "content": "Hello, how are you?"}, {"role": "assistant", "content": "I'm doing great. How can I help you today?"}, {"role": "user", "content": "I'd like to show off how chat templating works!"},] tokenizer.apply\_chat\_template(chat, tokenize=False) I get the error message: ValueError: Cannot use apply\_chat\_template() because tokenizer.…
