5
5
#include " json-schema-to-grammar.h"
6
6
#include " log.h"
7
7
#include " regex-partial.h"
8
- #include " parsers/harmony.h"
9
8
10
9
#include < minja/chat-template.hpp>
11
10
#include < minja/minja.hpp>
@@ -1366,6 +1365,15 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1366
1365
static const common_regex browser_tool_call_regex (" browser\\ .(search|open|find)[\\ s\\ S]*<\\ |message\\ |>" );
1367
1366
static const common_regex python_tool_call_regex (" python\\ s?(?:<|constrain|>code)?<\\ |message\\ |>" );
1368
1367
1368
+ auto consume_until_start = [&]() {
1369
+ if (auto res = builder.try_find_regex (start_regex, std::string::npos, false )) {
1370
+ auto begin = res->groups [0 ].begin ;
1371
+ builder.move_to (begin);
1372
+ return res->prelude ;
1373
+ }
1374
+ return builder.consume_rest ();
1375
+ };
1376
+
1369
1377
auto tool_call = [&]() {
1370
1378
if (auto res = builder.try_consume_regex (user_tool_call_regex)) {
1371
1379
auto name = builder.str (res->groups [1 ]);
@@ -1379,7 +1387,7 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1379
1387
auto args = builder.consume_rest ();
1380
1388
LOG_DBG (" builtin tool call to browser.%s %s" , name.c_str (), args.c_str ());
1381
1389
} else {
1382
- throw common_chat_msg_parse_exception (" expected function call" );
1390
+ throw common_chat_msg_parse_exception (" expected function call, got: " + consume_until_start () );
1383
1391
}
1384
1392
};
1385
1393
@@ -1391,15 +1399,15 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1391
1399
builder.add_content (builder.consume_rest ());
1392
1400
}
1393
1401
} else {
1394
- throw common_chat_msg_parse_exception (" expected: \" to=\" or <|message|>" );
1402
+ throw common_chat_msg_parse_exception (" expected: \" to=\" or <|message|>, got: " + consume_until_start () );
1395
1403
}
1396
1404
};
1397
1405
1398
1406
auto final = [&]() {
1399
1407
if (builder.try_consume_regex (message_regex)) {
1400
1408
builder.add_content (builder.consume_rest ());
1401
1409
} else {
1402
- throw common_chat_msg_parse_exception (" expected: <|message|>" );
1410
+ throw common_chat_msg_parse_exception (" expected: <|message|>, got: " + consume_until_start () );
1403
1411
}
1404
1412
};
1405
1413
@@ -1413,7 +1421,7 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1413
1421
builder.add_reasoning_content (builder.consume_rest ());
1414
1422
}
1415
1423
} else {
1416
- throw common_chat_msg_parse_exception (" expected: <|message|>" );
1424
+ throw common_chat_msg_parse_exception (" expected: <|message|>, got: " + consume_until_start () );
1417
1425
}
1418
1426
};
1419
1427
@@ -1430,30 +1438,30 @@ static void common_chat_parse_gpt_oss(common_chat_msg_parser & builder) {
1430
1438
}
1431
1439
}
1432
1440
} else {
1433
- throw common_chat_msg_parse_exception (" expected: <|channel|>" );
1441
+ throw common_chat_msg_parse_exception (" expected: <|channel|>, got: " + consume_until_start () );
1434
1442
}
1435
1443
};
1436
1444
1437
1445
auto start = [&]() {
1438
1446
if (builder.try_consume_regex (assistant_regex)) {
1439
1447
channel ();
1440
1448
} else {
1441
- throw common_chat_msg_parse_exception (" expected: <|assistant|>" );
1449
+ throw common_chat_msg_parse_exception (" expected: <|assistant|>, got: " + consume_until_start () );
1442
1450
}
1443
1451
};
1444
1452
1445
1453
try {
1446
1454
channel ();
1447
1455
} catch (const common_chat_msg_parse_exception & e) {
1448
- LOG_ERR (" Parse error: %s" , e.what ());
1456
+ LOG_ERR (" Parse error: %s\n " , e.what ());
1449
1457
}
1450
1458
1451
1459
// Read in complete messages until done or partial exception raised
1452
1460
while (builder.try_find_literal (" <|start|>" )) {
1453
1461
try {
1454
1462
start ();
1455
1463
} catch (const common_chat_msg_parse_exception & e) {
1456
- LOG_ERR (" Parse error: %s" , e.what ());
1464
+ LOG_ERR (" Parse error: %s\n " , e.what ());
1457
1465
}
1458
1466
}
1459
1467
0 commit comments