Skip to content

Commit 71c2c7f

Browse files
committed
server : fix validate_model_chat_template
1 parent 54ef9cf commit 71c2c7f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

examples/server/server.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,15 @@ struct server_context {
655655
}
656656

657657
bool validate_model_chat_template() const {
658-
llama_chat_message chat[] = {{"user", "test"}};
659-
660-
const int res = llama_chat_apply_template(model, nullptr, chat, 1, true, nullptr, 0);
661-
662-
return res > 0;
658+
std::vector<char> model_template(2048, 0); // longest known template is about 1200 bytes
659+
std::string template_key = "tokenizer.chat_template";
660+
int32_t res = llama_model_meta_val_str(model, template_key.c_str(), model_template.data(), model_template.size());
661+
if (res >= 0) {
662+
llama_chat_message chat[] = {{"user", "test"}};
663+
std::string tmpl = std::string(model_template.data(), model_template.size());
664+
res = llama_chat_apply_template(model, tmpl.c_str(), chat, 1, true, nullptr, 0);
665+
}
666+
return res >= 0;
663667
}
664668

665669
void init() {

0 commit comments

Comments
 (0)