assistant: Normalize line endings for prompts loaded from templates (#16808)

Closes #16804

Similar to #15708, when reading prompts from a template, both Windows
and Linux might end up with `CRLF (\r\n)` line endings, which can result
in a panic.

Release Notes:

- N/A
This commit is contained in:
张小白 2024-08-26 22:34:20 +08:00 committed by GitHub
parent a28700a74d
commit 5ee4c036f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View file

@ -3041,4 +3041,12 @@ impl LineEnding {
text
}
}
pub fn normalize_cow(text: Cow<str>) -> Cow<str> {
if let Cow::Owned(replaced) = LINE_SEPARATORS_REGEX.replace_all(&text, "\n") {
replaced.into()
} else {
text
}
}
}