Commit 6e02144
authored
fix: handle malformed messages missing <|message|> token (#82)
* fix: handle malformed messages missing <|message|> token
StreamableParser now gracefully handles LLM output where stop tokens
appear before the expected <|message|> token. The parser extracts
header metadata (channel, recipient, content_type) from accumulated
tokens and treats the remainder as message content.
Refactors header parsing into a shared helper to eliminate duplication.
Signed-off-by: Ben Browning <[email protected]>
* Keep backwards compatibility with new ParseOptions
This moves the more less strict parsing behavior behind a new
ParseOptions.strict value. It keeps all Rust signatures the same, adding
new `_with_options` variants where we need to pass in options. For
Python and wasm bindings, it adds the `strict` field as an optional
kwarg.
Signed-off-by: Ben Browning <[email protected]>
---------
Author: Ben Browning <[email protected]>1 parent 508cbaa commit 6e02144
File tree
10 files changed
+332
-49
lines changed- docs
- python/openai_harmony
- src
- tests
10 files changed
+332
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
111 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
| |||
269 | 273 | | |
270 | 274 | | |
271 | 275 | | |
272 | | - | |
| 276 | + | |
273 | 277 | | |
274 | 278 | | |
275 | 279 | | |
| |||
301 | 305 | | |
302 | 306 | | |
303 | 307 | | |
304 | | - | |
| 308 | + | |
305 | 309 | | |
306 | 310 | | |
307 | 311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
114 | 116 | | |
115 | | - | |
| 117 | + | |
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
| 95 | + | |
| 96 | + | |
94 | 97 | | |
95 | 98 | | |
96 | | - | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
523 | | - | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
524 | 528 | | |
525 | 529 | | |
526 | | - | |
| 530 | + | |
527 | 531 | | |
528 | 532 | | |
529 | 533 | | |
| |||
619 | 623 | | |
620 | 624 | | |
621 | 625 | | |
622 | | - | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
623 | 633 | | |
624 | | - | |
| 634 | + | |
625 | 635 | | |
626 | 636 | | |
627 | 637 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
| 372 | + | |
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
376 | 377 | | |
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
380 | | - | |
| 381 | + | |
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
387 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
388 | 404 | | |
389 | 405 | | |
390 | 406 | | |
| |||
1019 | 1035 | | |
1020 | 1036 | | |
1021 | 1037 | | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1022 | 1049 | | |
1023 | 1050 | | |
1024 | 1051 | | |
| |||
1032 | 1059 | | |
1033 | 1060 | | |
1034 | 1061 | | |
| 1062 | + | |
1035 | 1063 | | |
1036 | 1064 | | |
1037 | 1065 | | |
| |||
1049 | 1077 | | |
1050 | 1078 | | |
1051 | 1079 | | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1052 | 1089 | | |
1053 | 1090 | | |
1054 | 1091 | | |
| |||
1068 | 1105 | | |
1069 | 1106 | | |
1070 | 1107 | | |
| 1108 | + | |
1071 | 1109 | | |
1072 | 1110 | | |
1073 | 1111 | | |
| |||
1123 | 1161 | | |
1124 | 1162 | | |
1125 | 1163 | | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
1126 | 1192 | | |
1127 | 1193 | | |
1128 | 1194 | | |
| |||
1194 | 1260 | | |
1195 | 1261 | | |
1196 | 1262 | | |
1197 | | - | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
1198 | 1270 | | |
1199 | | - | |
| 1271 | + | |
1200 | 1272 | | |
1201 | | - | |
1202 | | - | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
1206 | | - | |
1207 | | - | |
| 1273 | + | |
| 1274 | + | |
1208 | 1275 | | |
1209 | 1276 | | |
1210 | 1277 | | |
| |||
1280 | 1347 | | |
1281 | 1348 | | |
1282 | 1349 | | |
| 1350 | + | |
1283 | 1351 | | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
| 1352 | + | |
1287 | 1353 | | |
1288 | 1354 | | |
1289 | 1355 | | |
| |||
1308 | 1374 | | |
1309 | 1375 | | |
1310 | 1376 | | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
1311 | 1391 | | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
1315 | | - | |
1316 | | - | |
1317 | 1392 | | |
1318 | 1393 | | |
1319 | 1394 | | |
1320 | 1395 | | |
1321 | 1396 | | |
1322 | 1397 | | |
1323 | 1398 | | |
1324 | | - | |
1325 | | - | |
1326 | | - | |
1327 | | - | |
1328 | | - | |
1329 | | - | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
1330 | 1432 | | |
1331 | 1433 | | |
1332 | 1434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
0 commit comments