Skip to content

Commit b2dd490

Browse files
author
Olivier Chafik
committed
add missing try catch around jinja parsing to default to chatml
1 parent aa98e59 commit b2dd490

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

common/common.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,13 +1920,22 @@ common_chat_templates common_chat_templates_from_model(const struct llama_model
19201920
token_bos = get_token(llama_vocab_bos(vocab), "BOS", "bos_token");
19211921
token_eos = get_token(llama_vocab_eos(vocab), "EOS", "eos_token");
19221922
#endif
1923-
return {
1924-
has_explicit_template,
1925-
std::make_unique<minja::chat_template>(default_template_src, token_bos, token_eos),
1926-
template_tool_use_src.empty()
1927-
? nullptr
1928-
: std::make_unique<minja::chat_template>(template_tool_use_src, token_bos, token_eos)
1929-
};
1923+
try {
1924+
return {
1925+
has_explicit_template,
1926+
std::make_unique<minja::chat_template>(default_template_src, token_bos, token_eos),
1927+
template_tool_use_src.empty()
1928+
? nullptr
1929+
: std::make_unique<minja::chat_template>(template_tool_use_src, token_bos, token_eos),
1930+
};
1931+
} catch (const std::exception & e) {
1932+
LOG_ERR("%s: failed to parse chat template: %s\n", __func__, e.what());
1933+
return {
1934+
has_explicit_template,
1935+
std::make_unique<minja::chat_template>(CHATML_TEMPLATE_SRC, token_bos, token_eos),
1936+
nullptr,
1937+
};
1938+
}
19301939
}
19311940

19321941
//

0 commit comments

Comments
 (0)