Skip to content

Commit 83eee1c

Browse files
authored
patch broken chat template
1 parent f5df812 commit 83eee1c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

convert_hf_to_gguf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6609,6 +6609,12 @@ def set_vocab(self):
66096609
special_vocab._set_special_token("unk", tokenizer.get_added_vocab()["<|endoftext|>"]) # 151329
66106610
special_vocab._set_special_token("eom", tokenizer.get_added_vocab()["<|observation|>"]) # 151338
66116611

6612+
# Patch broken chat template
6613+
if special_vocab.chat_template and "visible_text(m.content).endswith" in special_vocab.chat_template:
6614+
special_vocab.chat_template = special_vocab.chat_template.replace(
6615+
"""{{ visible_text(m.content) }}\n{{- '/nothink' if (enable_thinking is defined and not enable_thinking and not visible_text(m.content).endswith("/nothink")) else '' -}}""",
6616+
"""{% set content = visible_text(m.content) %}{{ content }}\n{{- '/nothink' if (enable_thinking is defined and not enable_thinking and not content.endswith("/nothink")) else '' -}}""")
6617+
66126618
special_vocab.add_to_gguf(self.gguf_writer)
66136619

66146620
def set_gguf_parameters(self):

0 commit comments

Comments
 (0)