|
10 | 10 | // CLI argument parsing |
11 | 11 | // |
12 | 12 |
|
13 | | -struct llama_arg { |
| 13 | +struct common_arg { |
14 | 14 | std::set<enum llama_example> examples = {LLAMA_EXAMPLE_COMMON}; |
15 | 15 | std::vector<const char *> args; |
16 | 16 | const char * value_hint = nullptr; // help text or example for arg value |
17 | 17 | const char * value_hint_2 = nullptr; // for second arg value |
18 | 18 | const char * env = nullptr; |
19 | 19 | std::string help; |
20 | 20 | bool is_sparam = false; // is current arg a sampling param? |
21 | | - void (*handler_void) (gpt_params & params) = nullptr; |
22 | | - void (*handler_string) (gpt_params & params, const std::string &) = nullptr; |
23 | | - void (*handler_str_str)(gpt_params & params, const std::string &, const std::string &) = nullptr; |
24 | | - void (*handler_int) (gpt_params & params, int) = nullptr; |
| 21 | + void (*handler_void) (common_params & params) = nullptr; |
| 22 | + void (*handler_string) (common_params & params, const std::string &) = nullptr; |
| 23 | + void (*handler_str_str)(common_params & params, const std::string &, const std::string &) = nullptr; |
| 24 | + void (*handler_int) (common_params & params, int) = nullptr; |
25 | 25 |
|
26 | | - llama_arg( |
| 26 | + common_arg( |
27 | 27 | const std::initializer_list<const char *> & args, |
28 | 28 | const char * value_hint, |
29 | 29 | const std::string & help, |
30 | | - void (*handler)(gpt_params & params, const std::string &) |
| 30 | + void (*handler)(common_params & params, const std::string &) |
31 | 31 | ) : args(args), value_hint(value_hint), help(help), handler_string(handler) {} |
32 | 32 |
|
33 | | - llama_arg( |
| 33 | + common_arg( |
34 | 34 | const std::initializer_list<const char *> & args, |
35 | 35 | const char * value_hint, |
36 | 36 | const std::string & help, |
37 | | - void (*handler)(gpt_params & params, int) |
| 37 | + void (*handler)(common_params & params, int) |
38 | 38 | ) : args(args), value_hint(value_hint), help(help), handler_int(handler) {} |
39 | 39 |
|
40 | | - llama_arg( |
| 40 | + common_arg( |
41 | 41 | const std::initializer_list<const char *> & args, |
42 | 42 | const std::string & help, |
43 | | - void (*handler)(gpt_params & params) |
| 43 | + void (*handler)(common_params & params) |
44 | 44 | ) : args(args), help(help), handler_void(handler) {} |
45 | 45 |
|
46 | 46 | // support 2 values for arg |
47 | | - llama_arg( |
| 47 | + common_arg( |
48 | 48 | const std::initializer_list<const char *> & args, |
49 | 49 | const char * value_hint, |
50 | 50 | const char * value_hint_2, |
51 | 51 | const std::string & help, |
52 | | - void (*handler)(gpt_params & params, const std::string &, const std::string &) |
| 52 | + void (*handler)(common_params & params, const std::string &, const std::string &) |
53 | 53 | ) : args(args), value_hint(value_hint), value_hint_2(value_hint_2), help(help), handler_str_str(handler) {} |
54 | 54 |
|
55 | | - llama_arg & set_examples(std::initializer_list<enum llama_example> examples); |
56 | | - llama_arg & set_env(const char * env); |
57 | | - llama_arg & set_sparam(); |
| 55 | + common_arg & set_examples(std::initializer_list<enum llama_example> examples); |
| 56 | + common_arg & set_env(const char * env); |
| 57 | + common_arg & set_sparam(); |
58 | 58 | bool in_example(enum llama_example ex); |
59 | 59 | bool get_value_from_env(std::string & output); |
60 | 60 | bool has_value_from_env(); |
61 | 61 | std::string to_string(); |
62 | 62 | }; |
63 | 63 |
|
64 | | -struct gpt_params_context { |
| 64 | +struct common_params_context { |
65 | 65 | enum llama_example ex = LLAMA_EXAMPLE_COMMON; |
66 | | - gpt_params & params; |
67 | | - std::vector<llama_arg> options; |
| 66 | + common_params & params; |
| 67 | + std::vector<common_arg> options; |
68 | 68 | void(*print_usage)(int, char **) = nullptr; |
69 | | - gpt_params_context(gpt_params & params) : params(params) {} |
| 69 | + common_params_context(common_params & params) : params(params) {} |
70 | 70 | }; |
71 | 71 |
|
72 | 72 | // parse input arguments from CLI |
73 | 73 | // if one argument has invalid value, it will automatically display usage of the specific argument (and not the full usage message) |
74 | | -bool gpt_params_parse(int argc, char ** argv, gpt_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr); |
| 74 | +bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr); |
75 | 75 |
|
76 | 76 | // function to be used by test-arg-parser |
77 | | -gpt_params_context gpt_params_parser_init(gpt_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr); |
| 77 | +common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr); |
0 commit comments