Skip to content

Commit

Permalink
fix(cpp): validateModelChatTemplate missing messages check
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 13, 2024
1 parent f35a963 commit c1d15a3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cpp/rn-llama.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,16 @@ struct llama_rn_context
}

bool validateModelChatTemplate() const {
llama_chat_message chat[] = {{"user", "test"}};

std::vector<char> model_template(2048, 0); // longest known template is about 1200 bytes
std::string template_key = "tokenizer.chat_template";
int32_t res = llama_model_meta_val_str(model, template_key.c_str(), model_template.data(), model_template.size());

return res >= 0;
if (res >= 0) {
llama_chat_message chat[] = {{"user", "test"}};
std::string tmpl = std::string(model_template.data(), model_template.size());
int32_t chat_res = llama_chat_apply_template(model, tmpl.c_str(), chat, 1, true, nullptr, 0);
return chat_res > 0;
}
return res > 0;
}

void truncatePrompt(std::vector<llama_token> &prompt_tokens) {
Expand Down

0 comments on commit c1d15a3

Please sign in to comment.