UTF-8-safe truncation to at most `max` bytes (never splits a multibyte char — repair prompts echo arbitrary model output, including CJK).
(s: &str, max: usize)
| 1093 | /// UTF-8-safe truncation to at most `max` bytes (never splits a multibyte char — |
| 1094 | /// repair prompts echo arbitrary model output, including CJK). |
| 1095 | fn truncate_utf8(s: &str, max: usize) -> &str { |
| 1096 | if s.len() <= max { |
| 1097 | return s; |
| 1098 | } |
| 1099 | let mut end = max; |
| 1100 | while end > 0 && !s.is_char_boundary(end) { |
| 1101 | end -= 1; |
| 1102 | } |
| 1103 | &s[..end] |
| 1104 | } |
| 1105 | |
| 1106 | /// Repair prompt for when nothing parseable was produced at all. |
| 1107 | fn build_parse_failure_repair(raw_text: &str) -> String { |