4
4
#include < cstring>
5
5
#include < fstream>
6
6
#include < regex>
7
+ #include < iostream>
8
+ #include < iterator>
9
+ #include < string>
10
+ #include < math.h>
7
11
8
12
#if defined(_MSC_VER) || defined(__MINGW32__)
9
13
#include < malloc.h> // using malloc.h with MSC/MINGW
@@ -21,6 +25,14 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
21
25
params.n_threads = std::stoi (argv[++i]);
22
26
} else if (arg == " -p" || arg == " --prompt" ) {
23
27
params.prompt = argv[++i];
28
+ } else if (arg == " -f" || arg == " --file" ) {
29
+
30
+ std::ifstream file (argv[++i]);
31
+
32
+ std::copy (std::istreambuf_iterator<char >(file),
33
+ std::istreambuf_iterator<char >(),
34
+ back_inserter (params.prompt ));
35
+
24
36
} else if (arg == " -n" || arg == " --n_predict" ) {
25
37
params.n_predict = std::stoi (argv[++i]);
26
38
} else if (arg == " --top_k" ) {
@@ -59,6 +71,8 @@ void gpt_print_usage(int argc, char ** argv, const gpt_params & params) {
59
71
fprintf (stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n " , params.n_threads );
60
72
fprintf (stderr, " -p PROMPT, --prompt PROMPT\n " );
61
73
fprintf (stderr, " prompt to start generation with (default: random)\n " );
74
+ fprintf (stderr, " -f FNAME, --file FNAME\n " );
75
+ fprintf (stderr, " prompt file to start generation.\n " );
62
76
fprintf (stderr, " -n N, --n_predict N number of tokens to predict (default: %d)\n " , params.n_predict );
63
77
fprintf (stderr, " --top_k N top-k sampling (default: %d)\n " , params.top_k );
64
78
fprintf (stderr, " --top_p N top-p sampling (default: %.1f)\n " , params.top_p );
0 commit comments