Skip to content

Commit 533a69e

Browse files
authored
add support for chat template jinja files
1 parent 5d46bab commit 533a69e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

gguf-py/gguf/vocab.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,18 @@ def _try_load_from_tokenizer_json(self, path: Path) -> bool:
245245
if not tokenizer_config:
246246
return True
247247
chat_template_alt = None
248-
chat_template_file = path / 'chat_template.json'
249-
if chat_template_file.is_file():
250-
with open(chat_template_file, encoding = 'utf-8') as f:
248+
chat_template_json = path / 'chat_template.json'
249+
chat_template_jinja = path / 'chat_template.jinja'
250+
if chat_template_jinja.is_file():
251+
with open(chat_template_jinja, encoding = 'utf-8') as f:
252+
chat_template_alt = f.read()
253+
if additional_templates := list((path / 'additional_chat_templates').glob('*.jinja')):
254+
chat_template_alt = [{'name': 'default', 'template': chat_template_alt}]
255+
for template_path in additional_templates:
256+
with open(template_path, encoding = 'utf-8') as fp:
257+
chat_template_alt.append({'name': template_path.stem, 'template': fp.read()})
258+
elif chat_template_json.is_file():
259+
with open(chat_template_json, encoding = 'utf-8') as f:
251260
chat_template_alt = json.load(f).get('chat_template')
252261
chat_template = tokenizer_config.get('chat_template', chat_template_alt)
253262
if chat_template is None or isinstance(chat_template, (str, list)):

0 commit comments

Comments
 (0)