@@ -1364,7 +1364,7 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1364
1364
);
1365
1365
static const common_regex builtin_tool_call_regex (" (?:browser|python)[\\ s\\ S]*<\\ |message\\ |>" );
1366
1366
1367
- auto consume_until_start = [&]() {
1367
+ auto consume_until_next = [&]() {
1368
1368
if (auto res = builder.try_find_regex (start_regex, std::string::npos, false )) {
1369
1369
auto begin = res->groups [0 ].begin ;
1370
1370
builder.move_to (begin);
@@ -1382,27 +1382,31 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1382
1382
builder.consume_rest ();
1383
1383
LOG_ERR (" builtin tool calls not implemented\n " );
1384
1384
} else {
1385
- throw common_chat_msg_parse_exception (" expected function call, got: " + consume_until_start ());
1385
+ throw common_chat_msg_parse_exception (" expected function call, got: " + consume_until_next ());
1386
1386
}
1387
1387
};
1388
1388
1389
1389
auto commentary = [&]() {
1390
1390
if (builder.try_consume_regex (to_regex)) {
1391
- tool_call ();
1391
+ if (builder.syntax ().parse_tool_calls ) {
1392
+ tool_call ();
1393
+ } else {
1394
+ consume_until_next ();
1395
+ }
1392
1396
} else if (builder.try_consume_regex (message_regex)) {
1393
1397
if (!builder.try_find_regex (end_regex)) {
1394
1398
builder.add_content (builder.consume_rest ());
1395
1399
}
1396
1400
} else {
1397
- throw common_chat_msg_parse_exception (" expected: \" to=\" or <|message|>, got: " + consume_until_start ());
1401
+ throw common_chat_msg_parse_exception (" expected: \" to=\" or <|message|>, got: " + consume_until_next ());
1398
1402
}
1399
1403
};
1400
1404
1401
1405
auto final = [&]() {
1402
1406
if (builder.try_consume_regex (message_regex)) {
1403
1407
builder.add_content (builder.consume_rest ());
1404
1408
} else {
1405
- throw common_chat_msg_parse_exception (" expected: <|message|>, got: " + consume_until_start ());
1409
+ throw common_chat_msg_parse_exception (" expected: <|message|>, got: " + consume_until_next ());
1406
1410
}
1407
1411
};
1408
1412
@@ -1416,7 +1420,7 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1416
1420
builder.add_reasoning_content (builder.consume_rest ());
1417
1421
}
1418
1422
} else {
1419
- throw common_chat_msg_parse_exception (" expected: <|message|>, got: " + consume_until_start ());
1423
+ throw common_chat_msg_parse_exception (" expected: <|message|>, got: " + consume_until_next ());
1420
1424
}
1421
1425
};
1422
1426
@@ -1433,15 +1437,15 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1433
1437
}
1434
1438
}
1435
1439
} else {
1436
- throw common_chat_msg_parse_exception (" expected: <|channel|>, got: " + consume_until_start ());
1440
+ throw common_chat_msg_parse_exception (" expected: <|channel|>, got: " + consume_until_next ());
1437
1441
}
1438
1442
};
1439
1443
1440
1444
auto start = [&]() {
1441
1445
if (builder.try_consume_regex (assistant_regex)) {
1442
1446
channel ();
1443
1447
} else {
1444
- throw common_chat_msg_parse_exception (" expected: <|assistant|>, got: " + consume_until_start ());
1448
+ throw common_chat_msg_parse_exception (" expected: <|assistant|>, got: " + consume_until_next ());
1445
1449
}
1446
1450
};
1447
1451
0 commit comments