Skip to content

Commit

Permalink
feat(cli): do not strip newlines from prompt files
Browse files Browse the repository at this point in the history
  • Loading branch information
philpax committed Jul 5, 2023
1 parent a4a6c54 commit 4177d5c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
utils/prompts/*.txt text eol=lf
20 changes: 2 additions & 18 deletions binaries/llm-cli/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,24 +555,8 @@ impl PromptFile {
}

pub fn read_prompt_file(path: &Path) -> eyre::Result<String> {
match std::fs::read_to_string(path) {
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();
}
Ok(prompt)
}
Err(err) => {
eyre::bail!("Could not read prompt file at {path:?}; error: {err}");
}
}
std::fs::read_to_string(path)
.wrap_err_with(|| format!("Could not read prompt file at {path:?}"))
}

#[derive(Parser, Debug)]
Expand Down
1 change: 1 addition & 0 deletions utils/prompts/alpaca.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Below is an instruction that describes a task. Write a response that appropriate
{{PROMPT}}

### Response:

2 changes: 1 addition & 1 deletion utils/prompts/pygmalion.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Assistant's Persona: Assistant is a highly intelligent language model trained to comply with user requests.
<START>
Assistant: How may I help you?
You: {{PROMPT}}
You: {{PROMPT}}
2 changes: 1 addition & 1 deletion utils/prompts/vicuna.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
A chat between a human ("User") and an AI assistant ("Assistant"). The assistant gives helpful, detailed, and polite answers to the human's questions.

Assistant: How may I help you?
User: {{PROMPT}}
User: {{PROMPT}}

0 comments on commit 4177d5c

Please sign in to comment.