Skip to content

Commit 264eab4

Browse files
authored
Fix null content for chat-template. (#75)
The nullptr cause `Test failed: basic_string: construction from null is not valid`. Change to use json j_null instead. Tests pass with `./scripts/tests.sh`
1 parent da98a14 commit 264eab4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

include/minja/chat-template.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ class chat_template {
165165
auto out_empty = try_raw_render(json::array({dummy_user_msg, {{"role", "assistant"}, {"content", ""}}}), {}, false);
166166
auto out_null = try_raw_render(json::array({dummy_user_msg, {{"role", "assistant"}, {"content", nullptr}}}), {}, false);
167167
caps_.requires_non_null_content = contains(out_empty, user_needle) && !contains(out_null, user_needle);
168-
168+
169+
json j_null;
169170
auto make_tool_calls_msg = [&](const json & tool_calls) {
170171
return json {
171172
{"role", "assistant"},
172-
{"content", caps_.requires_non_null_content? "" : nullptr},
173+
{"content", caps_.requires_non_null_content? "" : j_null},
173174
{"tool_calls", tool_calls},
174175
};
175176
};
@@ -235,7 +236,7 @@ class chat_template {
235236
};
236237
const json tool_call_msg {
237238
{"role", "assistant"},
238-
{"content", caps_.requires_non_null_content ? "" : nullptr},
239+
{"content", caps_.requires_non_null_content ? "" : j_null},
239240
{"tool_calls", json::array({
240241
{
241242
// TODO: detect if requires numerical id or fixed length == 6 like Nemo

0 commit comments

Comments
 (0)