From bcaf91eed0199a5a23563c2fdfd500aefdb7d7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Sat, 1 Mar 2025 11:45:25 +0100 Subject: [PATCH 1/5] Add --system-prompt parameter --- common/arg.cpp | 11 ++++++++--- common/common.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/common/arg.cpp b/common/arg.cpp index 3c169b5b5f48e..b0909979b22c6 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -813,13 +813,18 @@ common_params_context common_params_parser_init(common_params & params, llama_ex ).set_env("LLAMA_ARG_FLASH_ATTN")); add_opt(common_arg( {"-p", "--prompt"}, "PROMPT", - ex == LLAMA_EXAMPLE_MAIN - ? "prompt to start generation with\nif -cnv is set, this will be used as system prompt" - : "prompt to start generation with", + "prompt to start generation with", [](common_params & params, const std::string & value) { params.prompt = value; } ).set_excludes({LLAMA_EXAMPLE_SERVER})); + add_opt(common_arg( + {"-sys", "--system-prompt"}, "PROMPT", + "system prompt to use with model (if applicable)", + [](common_params & params, const std::string & value) { + params.system_prompt = value; + } + ).set_examples({LLAMA_EXAMPLE_MAIN})); add_opt(common_arg( {"--no-perf"}, string_format("disable internal libllama performance timings (default: %s)", params.no_perf ? "true" : "false"), diff --git a/common/common.h b/common/common.h index efe8e7f796521..5973677e83f02 100644 --- a/common/common.h +++ b/common/common.h @@ -261,6 +261,7 @@ struct common_params { std::string hf_repo = ""; // HF repo // NOLINT std::string hf_file = ""; // HF file // NOLINT std::string prompt = ""; // NOLINT + std::string system_prompt = ""; // NOLINT std::string prompt_file = ""; // store the external prompt file name // NOLINT std::string path_prompt_cache = ""; // path to file for saving/loading prompt eval state // NOLINT std::string input_prefix = ""; // string to prefix user inputs with // NOLINT From ac6de5ac99d37baab06f9ac94b2a59da76777a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Sat, 1 Mar 2025 11:46:52 +0100 Subject: [PATCH 2/5] use user defined system prompt --- examples/main/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index cf8659b037ee3..7c6ab0470ed92 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -276,7 +276,7 @@ int main(int argc, char ** argv) { { auto prompt = (params.conversation_mode && params.enable_chat_template) // format the system prompt in conversation mode (fallback to default if empty) - ? chat_add_and_format("system", params.prompt.empty() ? DEFAULT_SYSTEM_MESSAGE : params.prompt) + ? chat_add_and_format("system", params.system_prompt.empty() ? DEFAULT_SYSTEM_MESSAGE : params.system_prompt) // otherwise use the prompt as is : params.prompt; if (params.interactive_first || !params.prompt.empty() || session_tokens.empty()) { From bfdfd4d4bfcf4e5c42d503d2ebd63da3daf7fd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Sat, 1 Mar 2025 12:04:15 +0100 Subject: [PATCH 3/5] clarify Co-authored-by: Xuan-Son Nguyen --- common/arg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/arg.cpp b/common/arg.cpp index b0909979b22c6..80f2373c4d967 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -820,7 +820,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex ).set_excludes({LLAMA_EXAMPLE_SERVER})); add_opt(common_arg( {"-sys", "--system-prompt"}, "PROMPT", - "system prompt to use with model (if applicable)", + "system prompt to use with model (if applicable, depending on chat template)", [](common_params & params, const std::string & value) { params.system_prompt = value; } From 2ec283aff84881ffbef38f8e81857c3e16489c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Sat, 1 Mar 2025 12:38:33 +0100 Subject: [PATCH 4/5] add warning --- examples/main/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 7c6ab0470ed92..a6dfdb4d466ac 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -219,6 +219,10 @@ int main(int argc, char ** argv) { // print chat template example in conversation mode if (params.conversation_mode) { if (params.enable_chat_template) { + if (!params.prompt.empty()) { + LOG_WRN("*** User-specified prompt in conversation mode will be ignored, did you mean to set --system-prompt (-sys) instead?\n"); + } + LOG_INF("%s: chat template example:\n%s\n", __func__, common_chat_format_example(chat_templates.get(), params.use_jinja).c_str()); } else { LOG_INF("%s: in-suffix/prefix is specified, chat template will be disabled\n", __func__); From 239c832bf8959a3e852a72ed6abacfd864fab9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Sat, 1 Mar 2025 12:40:20 +0100 Subject: [PATCH 5/5] clarify Co-authored-by: Xuan-Son Nguyen --- common/arg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/arg.cpp b/common/arg.cpp index 80f2373c4d967..5924c68c74cf2 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -813,7 +813,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex ).set_env("LLAMA_ARG_FLASH_ATTN")); add_opt(common_arg( {"-p", "--prompt"}, "PROMPT", - "prompt to start generation with", + "prompt to start generation with; for system message, use -sys", [](common_params & params, const std::string & value) { params.prompt = value; }