Skip to content

Commit

Permalink
Add check for not empty rendered chat template
Browse files Browse the repository at this point in the history
  • Loading branch information
yatarkan committed Jan 16, 2025
1 parent bba7b87 commit 0395d41
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cpp/src/tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,18 @@ class Tokenizer::TokenizerImpl {
{"slice", slice_callable},
};

std::string result;
try {
return tpl.RenderAsString(params).value();
result = tpl.RenderAsString(params).value();
} catch (const std::exception& error) {
OPENVINO_THROW("Chat template for the current model is not supported by Jinja2Cpp. "
"Please apply template manually to your prompt before calling generate. "
"For example: <start_of_turn>user{user_prompt}<end_of_turn><start_of_turn>model");
}
OPENVINO_ASSERT(!result.empty(), "Applied chat template resulted in an empty string. "
"Please check the chat template or apply template manually to your prompt before calling generate."
"For example: <start_of_turn>user{user_prompt}<end_of_turn><start_of_turn>model");
return result;
}

void set_chat_template(const std::string& chat_template) {
Expand Down

0 comments on commit 0395d41

Please sign in to comment.