Commit 74d22f3
committed
fix: Add JSON recovery for truncated streaming responses from kimi-k2 (#367)
- Add attemptJSONParse() function with recovery strategies for truncated/malformed JSON
- Handle incomplete JSON structures by closing them (}, ]}, }]}, etc.)
- Improve error handling and logging for malformed chunks
- Gracefully degrade when parsing fails instead of crashing
- Fixes issue where kimi-k2 model breaks off due to JSON truncation at newline boundaries1 parent a15bfeb commit 74d22f3
1 file changed
+4
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | | - | |
24 | 21 | | |
| 22 | + | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
725 | 724 | | |
726 | 725 | | |
727 | 726 | | |
728 | | - | |
| 727 | + | |
729 | 728 | | |
730 | 729 | | |
731 | 730 | | |
| |||
0 commit comments