Do not process prompts containing binary data for escapes (#33)

Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
This commit is contained in:
Kawrakow
2024-09-02 09:18:48 +03:00
committed by GitHub
parent 59c2e77869
commit 2db35edf71
2 changed files with 7 additions and 1 deletions

View File

@@ -250,7 +250,9 @@ bool gpt_params_parse_ex(int argc, char ** argv, gpt_params & params) {
gpt_params_handle_hf_token(params);
if (params.escape) {
string_process_escapes(params.prompt);
if (!params.prompt_is_binary) {
string_process_escapes(params.prompt);
}
string_process_escapes(params.input_prefix);
string_process_escapes(params.input_suffix);
string_process_escapes(sparams.cfg_negative_prompt);
@@ -334,6 +336,7 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
if (arg == "-p" || arg == "--prompt") {
CHECK_ARG
params.prompt = argv[i];
params.prompt_is_binary = false;
return true;
}
if (arg == "-e" || arg == "--escape") {
@@ -371,6 +374,7 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
ss << file.rdbuf();
params.prompt = ss.str();
fprintf(stderr, "Read %zu bytes from binary file %s\n", params.prompt.size(), argv[i]);
params.prompt_is_binary = true;
return true;
}
if (arg == "-f" || arg == "--file") {
@@ -387,6 +391,7 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
if (!params.prompt.empty() && params.prompt.back() == '\n') {
params.prompt.pop_back();
}
params.prompt_is_binary = false;
return true;
}
if (arg == "--in-file") {

View File

@@ -122,6 +122,7 @@ struct gpt_params {
std::string hf_file = ""; // HF file
std::string prompt = "";
std::string prompt_file = ""; // store the external prompt file name
bool prompt_is_binary = false; // don't fool around when the prompt contains binary data (as it is for multiple choice)
std::string path_prompt_cache = ""; // path to file for saving/loading prompt eval state
std::string input_prefix = ""; // string to prefix user inputs with
std::string input_suffix = ""; // string to suffix user inputs with