| 1033 | } |
| 1034 | |
| 1035 | static void common_params_print_completion(common_params_context & ctx_arg) { |
| 1036 | std::vector<common_arg *> common_options; |
| 1037 | std::vector<common_arg *> sparam_options; |
| 1038 | std::vector<common_arg *> specific_options; |
| 1039 | |
| 1040 | for (auto & opt : ctx_arg.options) { |
| 1041 | if (opt.is_sparam) { |
| 1042 | sparam_options.push_back(&opt); |
| 1043 | } else if (opt.in_example(ctx_arg.ex)) { |
| 1044 | specific_options.push_back(&opt); |
| 1045 | } else { |
| 1046 | common_options.push_back(&opt); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | printf("_llama_completions() {\n"); |
| 1051 | printf(" local cur prev opts\n"); |
| 1052 | printf(" COMPREPLY=()\n"); |
| 1053 | printf(" cur=\"${COMP_WORDS[COMP_CWORD]}\"\n"); |
| 1054 | printf(" prev=\"${COMP_WORDS[COMP_CWORD-1]}\"\n\n"); |
| 1055 | |
| 1056 | printf(" opts=\""); |
| 1057 | auto print_options = [](const std::vector<common_arg *> & options) { |
| 1058 | for (const common_arg * opt : options) { |
| 1059 | for (const char * arg : opt->args) { |
| 1060 | printf("%s ", arg); |
| 1061 | } |
| 1062 | } |
| 1063 | }; |
| 1064 | |
| 1065 | print_options(common_options); |
| 1066 | print_options(sparam_options); |
| 1067 | print_options(specific_options); |
| 1068 | printf("\"\n\n"); |
| 1069 | |
| 1070 | printf(" case \"$prev\" in\n"); |
| 1071 | printf(" --model)\n"); |
| 1072 | printf(" COMPREPLY=( $(compgen -f -X '!*.gguf' -- \"$cur\") $(compgen -d -- \"$cur\") )\n"); |
| 1073 | printf(" return 0\n"); |
| 1074 | printf(" ;;\n"); |
| 1075 | printf(" --grammar-file)\n"); |
| 1076 | printf(" COMPREPLY=( $(compgen -f -X '!*.gbnf' -- \"$cur\") $(compgen -d -- \"$cur\") )\n"); |
| 1077 | printf(" return 0\n"); |
| 1078 | printf(" ;;\n"); |
| 1079 | printf(" --chat-template-file)\n"); |
| 1080 | printf(" COMPREPLY=( $(compgen -f -X '!*.jinja' -- \"$cur\") $(compgen -d -- \"$cur\") )\n"); |
| 1081 | printf(" return 0\n"); |
| 1082 | printf(" ;;\n"); |
| 1083 | printf(" *)\n"); |
| 1084 | printf(" COMPREPLY=( $(compgen -W \"${opts}\" -- \"$cur\") )\n"); |
| 1085 | printf(" return 0\n"); |
| 1086 | printf(" ;;\n"); |
| 1087 | printf(" esac\n"); |
| 1088 | printf("}\n\n"); |
| 1089 | |
| 1090 | std::set<std::string> executables = { |
| 1091 | "llama-batched", |
| 1092 | "llama-batched-bench", |
no test coverage detected