Skip to content

Add flag to make reverse prompt case insensitive #2233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
params.export_cgraph = true;
} else if (arg == "--verbose-prompt") {
params.verbose_prompt = true;
} else if (arg == "-r" || arg == "--reverse-prompt") {
} else if (arg == "-r_ci" || arg == "--reverse_prompt_case_insensitive") {
params.reverse_prompt_case_insensitive = true;
}
else if (arg == "-r" || arg == "--reverse-prompt") {
if (++i >= argc) {
invalid_param = true;
break;
Expand Down Expand Up @@ -465,6 +468,7 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
fprintf(stderr, " -ins, --instruct run in instruction mode (use with Alpaca models)\n");
fprintf(stderr, " --multiline-input allows you to write or paste multiple lines without ending each in '\\'\n");
fprintf(stderr, " -r PROMPT, --reverse-prompt PROMPT\n");
fprintf(stderr, " -r_ci make the check for the reverse prompt case insensitive\n");
fprintf(stderr, " halt generation at PROMPT, return control in interactive mode\n");
fprintf(stderr, " (can be specified more than once for multiple prompts).\n");
fprintf(stderr, " --color colorise output to distinguish prompt and user input from generations\n");
Expand Down
1 change: 1 addition & 0 deletions examples/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct gpt_params {
bool numa = false; // attempt optimizations that help on some NUMA systems
bool export_cgraph = false; // export the computation graph
bool verbose_prompt = false; // print prompt tokens before generation
bool reverse_prompt_case_insensitive = false; // make the reverse prompt case insensitive
};

bool gpt_params_parse(int argc, char ** argv, gpt_params & params);
Expand Down
7 changes: 7 additions & 0 deletions examples/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "llama.h"
#include "build-info.h"

#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cmath>
Expand Down Expand Up @@ -665,6 +666,12 @@ int main(int argc, char ** argv) {
? last_output.length() - static_cast<size_t>(antiprompt.length() + extra_padding)
: 0;

if (params.reverse_prompt_case_insensitive) {
// convert both strings to lower case
std::transform(antiprompt.begin(), antiprompt.end(), antiprompt.begin(), ::tolower);
std::transform(last_output.begin(), last_output.end(), last_output.begin(), ::tolower);
}

if (last_output.find(antiprompt.c_str(), search_start_pos) != std::string::npos) {
if (params.interactive) {
is_interacting = true;
Expand Down