MCPcopy
hub / github.com/huggingface/alignment-handbook / maybe_insert_system_message

Function maybe_insert_system_message

src/alignment/data.py:28–39  ·  view source on GitHub ↗
(messages, tokenizer)

Source from the content-addressed store, hash-verified

26
27
28def 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
42def apply_chat_template(

Callers 2

apply_chat_templateFunction · 0.85

Calls

no outgoing calls

Tested by 1