@@ -30,7 +30,14 @@ extern "C" __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int
30
30
#define CP_UTF8 65001
31
31
#endif
32
32
33
+ <<<<<<< HEAD
33
34
int32_t get_num_physical_cores () {
35
+ =======
36
+
37
+ bool gpt_params_parse (int argc, char ** argv, gpt_params & params) {
38
+ // determine sensible default number of threads.
39
+ // std::thread::hardware_concurrency may not be equal to the number of cores, or may return 0.
40
+ >>>>>>> 7f8e899 (Process escape sequences given in prompts)
34
41
#ifdef __linux__
35
42
std::ifstream cpuinfo (" /proc/cpuinfo" );
36
43
std::string line;
@@ -66,6 +73,33 @@ int32_t get_num_physical_cores() {
66
73
return n_threads > 0 ? (n_threads <= 4 ? n_threads : n_threads / 2 ) : 4 ;
67
74
}
68
75
76
+ std::string process_escapes (const char * input) {
77
+ std::string output;
78
+
79
+ if (input != nullptr ) {
80
+ std::size_t input_len = std::strlen (input);
81
+ output.reserve (input_len);
82
+
83
+ for (std::size_t i = 0 ; i < input_len; ++i) {
84
+ if (input[i] == ' \\ ' && i + 1 < input_len) {
85
+ switch (input[++i]) {
86
+ case ' n' : output.push_back (' \n ' ); break ;
87
+ case ' t' : output.push_back (' \t ' ); break ;
88
+ case ' \' ' : output.push_back (' \' ' ); break ;
89
+ case ' \" ' : output.push_back (' \" ' ); break ;
90
+ case ' \\ ' : output.push_back (' \\ ' ); break ;
91
+ default : output.push_back (' \\ ' );
92
+ output.push_back (input[i]); break ;
93
+ }
94
+ } else {
95
+ output.push_back (input[i]);
96
+ }
97
+ }
98
+ }
99
+
100
+ return output;
101
+ }
102
+
69
103
bool gpt_params_parse (int argc, char ** argv, gpt_params & params) {
70
104
bool invalid_param = false ;
71
105
std::string arg;
@@ -91,7 +125,7 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
91
125
invalid_param = true ;
92
126
break ;
93
127
}
94
- params.prompt = argv[i];
128
+ params.prompt = process_escapes ( argv[i]) ;
95
129
} else if (arg == " --session" ) {
96
130
if (++i >= argc) {
97
131
invalid_param = true ;
0 commit comments