The apply_chat_template function is probably more primitive than you think. It literally just takes a text template and puts it together with the model, and at runtime the tokenizer reads it and converts the OpenAI-style format list[dict] to str.
I don’t think the OpenAI-style format is standardized in any way, it’s just something that’s convenient to use. To be precise, it’s a little different for each software…
Well, it’s easy to use.
Ah great. Thanks.
So it’s just a matter of serialization of structured messages into a text input
Still the question around the standards. It was mentioned in referred docs it uses Jinja as a templater. Yet it seems not all the models follow this as well.
E.g. Gemmas something go-like style
{{- range $i, $_ := .Messages }}
so how apply_chat_template knows how to render them in general?
And regarding input structure it self. Are at least .messages.role and .content are some how basic structure or these could vary as well?
Even though it is an OpenAI-style format, it is not an OpenAI class. It must be a list[dict] with a similar feel…
For more information on the template format, see below.
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!"},
]