summaryrefslogtreecommitdiff
path: root/llama.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llama.cpp')
-rw-r--r--llama.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/llama.cpp b/llama.cpp
index b27aa272..47809964 100644
--- a/llama.cpp
+++ b/llama.cpp
@@ -13541,18 +13541,22 @@ LLAMA_API int32_t llama_chat_apply_template(
curr_tmpl = std::string(model_template.data(), model_template.size());
}
}
+
// format the chat to string
std::vector<const llama_chat_message *> chat_vec;
chat_vec.resize(n_msg);
for (size_t i = 0; i < n_msg; i++) {
chat_vec[i] = &chat[i];
}
+
std::string formatted_chat;
int32_t res = llama_chat_apply_template_internal(curr_tmpl, chat_vec, formatted_chat, add_ass);
if (res < 0) {
return res;
}
- strncpy(buf, formatted_chat.c_str(), length);
+ if (buf && length > 0) {
+ strncpy(buf, formatted_chat.c_str(), length);
+ }
return res;
}