| 1181 | } |
| 1182 | |
| 1183 | bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **)) { |
| 1184 | auto ctx_arg = common_params_parser_init(params, ex, print_usage); |
| 1185 | const common_params params_org = ctx_arg.params; // the example can modify the default params |
| 1186 | |
| 1187 | try { |
| 1188 | if (!common_params_parse_ex(argc, argv, ctx_arg)) { |
| 1189 | ctx_arg.params = params_org; |
| 1190 | return false; |
| 1191 | } |
| 1192 | if (ctx_arg.params.usage) { |
| 1193 | common_params_print_usage(ctx_arg); |
| 1194 | if (ctx_arg.print_usage) { |
| 1195 | ctx_arg.print_usage(argc, argv); |
| 1196 | } |
| 1197 | exit(0); |
| 1198 | } |
| 1199 | if (ctx_arg.params.completion) { |
| 1200 | common_params_print_completion(ctx_arg); |
| 1201 | exit(0); |
| 1202 | } |
| 1203 | } catch (const std::invalid_argument & ex) { |
| 1204 | fprintf(stderr, "%s\n", ex.what()); |
| 1205 | ctx_arg.params = params_org; |
| 1206 | return false; |
| 1207 | } catch (std::exception & ex) { |
| 1208 | fprintf(stderr, "%s\n", ex.what()); |
| 1209 | exit(1); // for other exceptions, we exit with status code 1 |
| 1210 | } |
| 1211 | |
| 1212 | return true; |
| 1213 | } |
| 1214 | |
| 1215 | static std::string list_builtin_chat_templates() { |
| 1216 | std::vector<const char *> supported_tmpl; |