@@ -175,6 +175,21 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
175175            if  (params.prompt .back () == ' \n '  ) {
176176                params.prompt .pop_back ();
177177            }
178+         } else  if  (arg == " -sysf"   || arg == " --system-file"  ) {
179+             if  (++i >= argc) {
180+                 invalid_param = true ;
181+                 break ;
182+             }
183+             std::ifstream file (argv[i]);
184+             if  (!file) {
185+                 fprintf (stderr, " error: failed to open file '%s'\n "  , argv[i]);
186+                 invalid_param = true ;
187+                 break ;
188+             }
189+             std::copy (std::istreambuf_iterator<char >(file), std::istreambuf_iterator<char >(), back_inserter (params.system_prompt ));
190+             if  (params.system_prompt .back () == ' \n '  ) {
191+                 params.system_prompt .pop_back ();
192+             }
178193        } else  if  (arg == " -n"   || arg == " --n-predict"  ) {
179194            if  (++i >= argc) {
180195                invalid_param = true ;
@@ -516,10 +531,11 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
516531    }
517532    if  (escape_prompt) {
518533        process_escapes (params.prompt );
534+         process_escapes (params.system_prompt );
519535    }
520536
521537
522-        bool  all_zero = true ;
538+     bool  all_zero = true ;
523539        for  (size_t  i = 0 ; i < LLAMA_MAX_DEVICES; ++i) {
524540            if  (params.tensor_split [i] != 0 .0f ) {
525541                all_zero = false ;
@@ -565,7 +581,7 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
565581    fprintf (stderr, "   -S, --stopwords \" ,,,\"  Add stopwords in addition to the usual end-of-sequence\n "  );
566582    fprintf (stderr, "                         comma separated list: -S \"\\ n,Hello World,stopword\"  - overwrites defaults except eos\n "  );
567583    fprintf (stderr, "                         Important: 'is' and ' is' are unique tokens in a stopword. Just as 'Hello' and ' Hello' are distinct\n "  );
568-     fprintf (stderr, "   -e                    process prompt  escapes sequences (\\ n, \\ r, \\ t, \\ ', \\\" , \\\\ )\n "  );
584+     fprintf (stderr, "   -e                    process escapes sequences in prompt and system message  (\\ n, \\ r, \\ t, \\ ', \\\" , \\\\ )\n "  );
569585    fprintf (stderr, "   --prompt-cache FNAME  file to cache prompt state for faster startup (default: none)\n "  );
570586    fprintf (stderr, "   --prompt-cache-all    if specified, saves user input and generations to cache as well.\n "  );
571587    fprintf (stderr, "                         not supported with --interactive or other interactive options\n "  );
@@ -575,6 +591,8 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
575591    fprintf (stderr, "   --in-suffix STRING    string to suffix after user inputs with (default: empty)\n "  );
576592    fprintf (stderr, "   -f FNAME, --file FNAME\n "  );
577593    fprintf (stderr, "                         read prompt from a file, optionally -p prompt is prefixed\n "  );
594+     fprintf (stderr, "   -sysf FNAME, --system-file FNAME\n "  );
595+     fprintf (stderr, "                         read system prompt from a file\n "  );
578596    fprintf (stderr, "   -n N, --n-predict N   number of tokens to predict (default: %d, -1 = infinity)\n "  , params.n_predict );
579597    fprintf (stderr, "   --top-k N             top-k sampling (default: %d, 0 = disabled)\n "  , params.top_k );
580598    fprintf (stderr, "   --top-p N             top-p sampling (default: %.1f, 1.0 = disabled)\n "  , (double )params.top_p );
0 commit comments