@@ -1188,11 +1188,11 @@ static common_chat_params common_chat_params_init_llama_3_x(const common_chat_te
1188
1188
1189
1189
static common_chat_params common_chat_params_init_nemotron_v2 (const common_chat_template & tmpl, const struct templates_params & inputs) {
1190
1190
common_chat_params data;
1191
-
1191
+
1192
1192
// Generate the prompt using the apply() function with the template
1193
1193
data.prompt = apply (tmpl, inputs);
1194
1194
data.format = COMMON_CHAT_FORMAT_NEMOTRON_V2;
1195
-
1195
+
1196
1196
// Handle thinking tags appropriately based on inputs.enable_thinking
1197
1197
if (string_ends_with (data.prompt , " <think>\n " )) {
1198
1198
if (!inputs.enable_thinking ) {
@@ -1201,7 +1201,7 @@ static common_chat_params common_chat_params_init_nemotron_v2(const common_chat_
1201
1201
data.thinking_forced_open = true ;
1202
1202
}
1203
1203
}
1204
-
1204
+
1205
1205
// When tools are present, build grammar for the <TOOLCALL> format
1206
1206
if (!inputs.tools .is_null () && inputs.tools .is_array () && !inputs.tools .empty ()) {
1207
1207
data.grammar_lazy = inputs.tool_choice != COMMON_CHAT_TOOL_CHOICE_REQUIRED;
@@ -1212,7 +1212,7 @@ static common_chat_params common_chat_params_init_nemotron_v2(const common_chat_
1212
1212
std::string name = function.at (" name" );
1213
1213
auto parameters = function.at (" parameters" );
1214
1214
builder.resolve_refs (parameters);
1215
-
1215
+
1216
1216
// Build tool call rule for Nemotron format
1217
1217
tool_rules.push_back (builder.add_rule (name + " -call" , builder.add_schema (name + " -args" , {
1218
1218
{" type" , " object" },
@@ -1223,17 +1223,17 @@ static common_chat_params common_chat_params_init_nemotron_v2(const common_chat_
1223
1223
{" required" , json::array ({" name" , " arguments" })},
1224
1224
})));
1225
1225
});
1226
-
1226
+
1227
1227
// Create tool call rule - Nemotron uses <TOOLCALL>[...] format
1228
1228
auto tool_call = builder.add_rule (" tool_call" , string_join (tool_rules, " | " ));
1229
1229
auto tool_list = builder.add_rule (" tool_list" , " \" [\" space " + tool_call + " (\" ,\" space " + tool_call + " )* space \" ]\" " );
1230
-
1230
+
1231
1231
// Grammar rule for <TOOLCALL> format
1232
1232
builder.add_rule (" root" ,
1233
1233
std::string (data.thinking_forced_open ? " ( \"\" space )? " : " " ) +
1234
1234
" \" <TOOLCALL>\" space " + tool_list + " \" </TOOLCALL>\" " );
1235
1235
});
1236
-
1236
+
1237
1237
// Define triggers for <TOOLCALL> token
1238
1238
data.grammar_triggers .push_back ({
1239
1239
COMMON_GRAMMAR_TRIGGER_TYPE_WORD,
@@ -1248,7 +1248,7 @@ static common_chat_params common_chat_params_init_nemotron_v2(const common_chat_
1248
1248
});
1249
1249
}
1250
1250
}
1251
-
1251
+
1252
1252
// Set preserved tokens for all special tokens
1253
1253
data.preserved_tokens = {
1254
1254
" <think>" ,
@@ -1260,7 +1260,7 @@ static common_chat_params common_chat_params_init_nemotron_v2(const common_chat_
1260
1260
" <AVAILABLE_TOOLS>" ,
1261
1261
" </AVAILABLE_TOOLS>"
1262
1262
};
1263
-
1263
+
1264
1264
return data;
1265
1265
}
1266
1266
static void common_chat_parse_llama_3_1 (common_chat_msg_parser & builder, bool with_builtin_tools = false ) {
0 commit comments