added --disable-tty
flag for interactive mode
This commit is contained in:
parent
2b2646931b
commit
a13e998a8a
3 changed files with 14 additions and 6 deletions
|
@ -344,6 +344,8 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
params.input_suffix = argv[i];
|
params.input_suffix = argv[i];
|
||||||
|
} else if (arg == "--disable-tty") {
|
||||||
|
params.disable_tty = true;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
|
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
|
||||||
gpt_print_usage(argc, argv, default_params);
|
gpt_print_usage(argc, argv, default_params);
|
||||||
|
@ -382,6 +384,7 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
|
||||||
fprintf(stderr, " run in interactive mode and poll user input upon seeing PROMPT (can be\n");
|
fprintf(stderr, " run in interactive mode and poll user input upon seeing PROMPT (can be\n");
|
||||||
fprintf(stderr, " specified more than once for multiple prompts).\n");
|
fprintf(stderr, " specified more than once for multiple prompts).\n");
|
||||||
fprintf(stderr, " --color colorise output to distinguish prompt and user input from generations\n");
|
fprintf(stderr, " --color colorise output to distinguish prompt and user input from generations\n");
|
||||||
|
fprintf(stderr, " --disable-tty disable the use of TTY in interactive mode in favor of stderr\n");
|
||||||
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1, use random seed for < 0)\n");
|
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1, use random seed for < 0)\n");
|
||||||
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
|
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
|
||||||
fprintf(stderr, " -p PROMPT, --prompt PROMPT\n");
|
fprintf(stderr, " -p PROMPT, --prompt PROMPT\n");
|
||||||
|
@ -503,7 +506,7 @@ struct llama_context * llama_init_from_gpt_params(const gpt_params & params) {
|
||||||
return lctx;
|
return lctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void console_init(console_state & con_st) {
|
void console_init(console_state & con_st, bool disable_tty) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// Windows-specific console initialization
|
// Windows-specific console initialization
|
||||||
DWORD dwMode = 0;
|
DWORD dwMode = 0;
|
||||||
|
@ -541,9 +544,13 @@ void console_init(console_state & con_st) {
|
||||||
new_termios.c_cc[VTIME] = 0;
|
new_termios.c_cc[VTIME] = 0;
|
||||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
|
tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
|
||||||
|
|
||||||
con_st.tty = fopen("/dev/tty", "w+");
|
if (!disable_tty) {
|
||||||
if (con_st.tty != nullptr) {
|
con_st.tty = fopen("/dev/tty", "w+");
|
||||||
con_st.out = con_st.tty;
|
if (con_st.tty != nullptr) {
|
||||||
|
con_st.out = con_st.tty;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
con_st.out = stderr;
|
||||||
}
|
}
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
|
@ -72,6 +72,7 @@ struct gpt_params {
|
||||||
bool use_mlock = false; // use mlock to keep model in memory
|
bool use_mlock = false; // use mlock to keep model in memory
|
||||||
bool mem_test = false; // compute maximum memory usage
|
bool mem_test = false; // compute maximum memory usage
|
||||||
bool verbose_prompt = false; // print prompt tokens before generation
|
bool verbose_prompt = false; // print prompt tokens before generation
|
||||||
|
bool disable_tty = false; // disable TTY mode
|
||||||
};
|
};
|
||||||
|
|
||||||
bool gpt_params_parse(int argc, char ** argv, gpt_params & params);
|
bool gpt_params_parse(int argc, char ** argv, gpt_params & params);
|
||||||
|
@ -125,7 +126,7 @@ struct console_state {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void console_init(console_state & con_st);
|
void console_init(console_state & con_st, bool disable_tty);
|
||||||
void console_cleanup(console_state & con_st);
|
void console_cleanup(console_state & con_st);
|
||||||
void console_set_color(console_state & con_st, console_color_t color);
|
void console_set_color(console_state & con_st, console_color_t color);
|
||||||
bool console_readline(console_state & con_st, std::string & line);
|
bool console_readline(console_state & con_st, std::string & line);
|
||||||
|
|
|
@ -59,7 +59,7 @@ int main(int argc, char ** argv) {
|
||||||
// (note for later: this is a slightly awkward choice)
|
// (note for later: this is a slightly awkward choice)
|
||||||
con_st.use_color = params.use_color;
|
con_st.use_color = params.use_color;
|
||||||
con_st.multiline_input = params.multiline_input;
|
con_st.multiline_input = params.multiline_input;
|
||||||
console_init(con_st);
|
console_init(con_st, params.disable_tty);
|
||||||
atexit([]() { console_cleanup(con_st); });
|
atexit([]() { console_cleanup(con_st); });
|
||||||
|
|
||||||
if (params.perplexity) {
|
if (params.perplexity) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue