Skip to content

Commit f385f8d

Browse files
authored
Allow using prompt files (#59)
1 parent 02f0c6f commit f385f8d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

utils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <cstring>
55
#include <fstream>
66
#include <regex>
7+
#include <iostream>
8+
#include <iterator>
9+
#include <string>
10+
#include <math.h>
711

812
#if defined(_MSC_VER) || defined(__MINGW32__)
913
#include <malloc.h> // using malloc.h with MSC/MINGW
@@ -21,6 +25,14 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
2125
params.n_threads = std::stoi(argv[++i]);
2226
} else if (arg == "-p" || arg == "--prompt") {
2327
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+
2436
} else if (arg == "-n" || arg == "--n_predict") {
2537
params.n_predict = std::stoi(argv[++i]);
2638
} else if (arg == "--top_k") {
@@ -59,6 +71,8 @@ void gpt_print_usage(int argc, char ** argv, const gpt_params & params) {
5971
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
6072
fprintf(stderr, " -p PROMPT, --prompt PROMPT\n");
6173
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");
6276
fprintf(stderr, " -n N, --n_predict N number of tokens to predict (default: %d)\n", params.n_predict);
6377
fprintf(stderr, " --top_k N top-k sampling (default: %d)\n", params.top_k);
6478
fprintf(stderr, " --top_p N top-p sampling (default: %.1f)\n", params.top_p);

0 commit comments

Comments
 (0)