Update run.cpp

This commit is contained in:
ochafik 2025-01-13 23:26:31 +00:00
parent a57bb94e29
commit 4daae0bfc7

View File

@ -720,14 +720,14 @@ static int apply_chat_template(const minja::chat_template & tmpl, LlamaData & ll
for (const auto & msg : llama_data.messages) { for (const auto & msg : llama_data.messages) {
messages.push_back({ messages.push_back({
{"role", msg.role}, {"role", msg.role},
{ "content", msg.content} {"content", msg.content},
}); });
} }
try { try {
auto result = tmpl.apply(messages, /* tools= */ json(), append); auto result = tmpl.apply(messages, /* tools= */ json(), append);
llama_data.fmtted.resize(result.size() + 1); llama_data.fmtted.resize(result.size() + 1);
memcpy(llama_data.fmtted.data(), result.c_str(), result.size() + 1); memcpy(llama_data.fmtted.data(), result.c_str(), result.size() + 1);
return llama_data.fmtted.size(); return result.size();
} catch (const std::exception & e) { } catch (const std::exception & e) {
printe("failed to render the chat template: %s\n", e.what()); printe("failed to render the chat template: %s\n", e.what());
return -1; return -1;