Skip to content

Commit 1decdf5

Browse files
committed
Process escape sequences given in prompts
1 parent 13b0c68 commit 1decdf5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/common.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,40 @@ extern "C" __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int
3030
#define CP_UTF8 65001
3131
#endif
3232

33+
<<<<<<< HEAD
3334
int32_t get_num_physical_cores() {
35+
=======
36+
std::string process_escapes(const char* input) {
37+
std::string output;
38+
39+
if (input != nullptr) {
40+
std::size_t input_len = std::strlen(input);
41+
output.reserve(input_len);
42+
43+
for (std::size_t i = 0; i < input_len; ++i) {
44+
if (input[i] == '\\' && i + 1 < input_len) {
45+
switch (input[++i]) {
46+
case 'n': output.push_back('\n'); break;
47+
case 't': output.push_back('\t'); break;
48+
case '\'': output.push_back('\''); break;
49+
case '\"': output.push_back('\"'); break;
50+
case '\\': output.push_back('\\'); break;
51+
default: output.push_back('\\');
52+
output.push_back(input[i]); break;
53+
}
54+
} else {
55+
output.push_back(input[i]);
56+
}
57+
}
58+
}
59+
60+
return output;
61+
}
62+
63+
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
64+
// determine sensible default number of threads.
65+
// std::thread::hardware_concurrency may not be equal to the number of cores, or may return 0.
66+
>>>>>>> 7f8e899 (Process escape sequences given in prompts)
3467
#ifdef __linux__
3568
std::ifstream cpuinfo("/proc/cpuinfo");
3669
std::string line;
@@ -91,13 +124,17 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
91124
invalid_param = true;
92125
break;
93126
}
127+
<<<<<<< HEAD
94128
params.prompt = argv[i];
95129
} else if (arg == "--session") {
96130
if (++i >= argc) {
97131
invalid_param = true;
98132
break;
99133
}
100134
params.path_session = argv[i];
135+
=======
136+
params.prompt = process_escapes(argv[i]);
137+
>>>>>>> 7f8e899 (Process escape sequences given in prompts)
101138
} else if (arg == "-f" || arg == "--file") {
102139
if (++i >= argc) {
103140
invalid_param = true;

0 commit comments

Comments
 (0)