Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from KerfuffleV2/feat-strip_prompt_file_last_nl
Browse files Browse the repository at this point in the history
Strip off last \r\n in the prompt file.
  • Loading branch information
philpax authored Mar 24, 2023
2 parents bf7bdbc + ed1f013 commit 91afe67
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion llama-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,19 @@ fn main() {

let prompt = if let Some(path) = &args.prompt_file {
match std::fs::read_to_string(path) {
Ok(prompt) => prompt,
Ok(mut prompt) => {
// Strip off the last character if it's exactly newline. Also strip off a single
// carriage return if it's there. Since String must be valid UTF-8 it should be
// guaranteed that looking at the string as bytes here is safe: UTF-8 non-ASCII
// bytes will always the high bit set.
if matches!(prompt.as_bytes().last(), Some(b'\n')) {
prompt.pop();
}
if matches!(prompt.as_bytes().last(), Some(b'\r')) {
prompt.pop();
}
prompt
}
Err(err) => {
log::error!("Could not read prompt file at {path}. Error {err}");
std::process::exit(1);
Expand Down

0 comments on commit 91afe67

Please sign in to comment.