(messages, tokenizer)
| 26 | |
| 27 | |
| 28 | def maybe_insert_system_message(messages, tokenizer): |
| 29 | if messages[0]["role"] == "system": |
| 30 | return |
| 31 | |
| 32 | # chat template can be one of two attributes, we check in order |
| 33 | chat_template = tokenizer.chat_template |
| 34 | if chat_template is None: |
| 35 | chat_template = tokenizer.get_chat_template() |
| 36 | |
| 37 | # confirm the jinja template refers to a system message before inserting |
| 38 | if "system" in chat_template or "<|im_start|>" in chat_template: |
| 39 | messages.insert(0, {"role": "system", "content": ""}) |
| 40 | |
| 41 | |
| 42 | def apply_chat_template( |
no outgoing calls