mirror of
https://github.com/RightNow-AI/openfang.git
synced 2026-07-30 06:32:17 +00:00
Merge pull request #1029 from zhujg007/main
Fix: Safe char boundary handling for UTF-8 string slicing
This commit is contained in:
@@ -435,11 +435,10 @@ async fn summarize_messages(
|
||||
let safe_start = if conversation_text.is_char_boundary(start) {
|
||||
start
|
||||
} else {
|
||||
conversation_text[start..]
|
||||
.char_indices()
|
||||
.next()
|
||||
.map(|(i, _)| start + i)
|
||||
.unwrap_or(conversation_text.len())
|
||||
// Find the nearest valid character boundary moving upward
|
||||
(start..conversation_text.len())
|
||||
.find(|&i| conversation_text.is_char_boundary(i))
|
||||
.unwrap_or(conversation_text.len())
|
||||
};
|
||||
conversation_text = conversation_text[safe_start..].to_string();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user