Skip to content

Commit 45a8e76

Browse files
CISCngxson
andauthored
common : add --system-prompt parameter, replace behavior of -p in conversation mode (#12131)
* Add --system-prompt parameter * use user defined system prompt * clarify Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com> * add warning * clarify Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com> --------- Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
1 parent 80c41dd commit 45a8e76

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

common/arg.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,18 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
813813
).set_env("LLAMA_ARG_FLASH_ATTN"));
814814
add_opt(common_arg(
815815
{"-p", "--prompt"}, "PROMPT",
816-
ex == LLAMA_EXAMPLE_MAIN
817-
? "prompt to start generation with\nif -cnv is set, this will be used as system prompt"
818-
: "prompt to start generation with",
816+
"prompt to start generation with; for system message, use -sys",
819817
[](common_params & params, const std::string & value) {
820818
params.prompt = value;
821819
}
822820
).set_excludes({LLAMA_EXAMPLE_SERVER}));
821+
add_opt(common_arg(
822+
{"-sys", "--system-prompt"}, "PROMPT",
823+
"system prompt to use with model (if applicable, depending on chat template)",
824+
[](common_params & params, const std::string & value) {
825+
params.system_prompt = value;
826+
}
827+
).set_examples({LLAMA_EXAMPLE_MAIN}));
823828
add_opt(common_arg(
824829
{"--no-perf"},
825830
string_format("disable internal libllama performance timings (default: %s)", params.no_perf ? "true" : "false"),

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ struct common_params {
261261
std::string hf_repo = ""; // HF repo // NOLINT
262262
std::string hf_file = ""; // HF file // NOLINT
263263
std::string prompt = ""; // NOLINT
264+
std::string system_prompt = ""; // NOLINT
264265
std::string prompt_file = ""; // store the external prompt file name // NOLINT
265266
std::string path_prompt_cache = ""; // path to file for saving/loading prompt eval state // NOLINT
266267
std::string input_prefix = ""; // string to prefix user inputs with // NOLINT

examples/main/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ int main(int argc, char ** argv) {
219219
// print chat template example in conversation mode
220220
if (params.conversation_mode) {
221221
if (params.enable_chat_template) {
222+
if (!params.prompt.empty()) {
223+
LOG_WRN("*** User-specified prompt in conversation mode will be ignored, did you mean to set --system-prompt (-sys) instead?\n");
224+
}
225+
222226
LOG_INF("%s: chat template example:\n%s\n", __func__, common_chat_format_example(chat_templates.get(), params.use_jinja).c_str());
223227
} else {
224228
LOG_INF("%s: in-suffix/prefix is specified, chat template will be disabled\n", __func__);
@@ -276,7 +280,7 @@ int main(int argc, char ** argv) {
276280
{
277281
auto prompt = (params.conversation_mode && params.enable_chat_template)
278282
// format the system prompt in conversation mode (fallback to default if empty)
279-
? chat_add_and_format("system", params.prompt.empty() ? DEFAULT_SYSTEM_MESSAGE : params.prompt)
283+
? chat_add_and_format("system", params.system_prompt.empty() ? DEFAULT_SYSTEM_MESSAGE : params.system_prompt)
280284
// otherwise use the prompt as is
281285
: params.prompt;
282286
if (params.interactive_first || !params.prompt.empty() || session_tokens.empty()) {

0 commit comments

Comments
 (0)