Skip to content

Commit e2161bd

Browse files
jhen0409arthw
authored andcommitted
server : fix incorrect res in validate_model_chat_template (ggml-org#10272)
* server : fix validate_model_chat_template * server : fix chat res
1 parent d916751 commit e2161bd

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

examples/server/server.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,16 @@ 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+
int32_t chat_res = llama_chat_apply_template(model, tmpl.c_str(), chat, 1, true, nullptr, 0);
665+
return chat_res > 0;
666+
}
667+
return false;
663668
}
664669

665670
void init() {

0 commit comments

Comments
 (0)