1717# define NOMINMAX
1818#endif
1919#include < windows.h>
20+ #include < shellapi.h>
2021#endif
2122
2223#define JSON_ASSERT GGML_ASSERT
@@ -302,7 +303,6 @@ static handle_model_result common_params_handle_model(struct common_params_model
302303
303304 if (!model.docker_repo .empty ()) {
304305 model.path = common_docker_resolve_model (model.docker_repo );
305- model.name = model.docker_repo ;
306306 } else if (!model.hf_repo .empty ()) {
307307 // If -m was used with -hf, treat the model "path" as the hf_file to download
308308 if (model.hf_file .empty () && !model.path .empty ()) {
@@ -322,7 +322,6 @@ static handle_model_result common_params_handle_model(struct common_params_model
322322 throw std::runtime_error (" failed to download model from Hugging Face" );
323323 }
324324
325- model.name = model.hf_repo ;
326325 model.path = download_result.model_path ;
327326
328327 if (!download_result.mmproj_path .empty ()) {
@@ -893,7 +892,44 @@ bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map<com
893892 return true ;
894893}
895894
895+ #ifdef _WIN32
896+ struct utf8_argv {
897+ std::vector<std::string> buf;
898+ std::vector<char *> ptrs;
899+ };
900+
901+ static utf8_argv make_utf8_argv () {
902+ utf8_argv out;
903+ int wargc = 0 ;
904+ LPWSTR * wargv = CommandLineToArgvW (GetCommandLineW (), &wargc);
905+ if (!wargv) return out;
906+
907+ out.buf .reserve (wargc);
908+ for (int i = 0 ; i < wargc; ++i) {
909+ int n = WideCharToMultiByte (CP_UTF8 , WC_ERR_INVALID_CHARS , wargv[i], -1 , nullptr , 0 , nullptr , nullptr );
910+ if (n <= 0 ) { out.buf .emplace_back (); continue ; }
911+ auto & s = out.buf .emplace_back ();
912+ s.resize (static_cast <size_t >(n - 1 ));
913+ (void )WideCharToMultiByte (CP_UTF8 , 0 , wargv[i], -1 , s.data (), n, nullptr , nullptr );
914+ }
915+ LocalFree (wargv);
916+
917+ out.ptrs .reserve (out.buf .size () + 1 );
918+ for (auto & s : out.buf ) out.ptrs .push_back (s.data ());
919+ out.ptrs .push_back (nullptr );
920+ return out;
921+ }
922+ #endif
923+
896924bool common_params_parse (int argc, char ** argv, common_params & params, llama_example ex, void (*print_usage)(int , char **)) {
925+ #ifdef _WIN32
926+ auto utf8 = make_utf8_argv ();
927+ if (!utf8.ptrs .empty ()) {
928+ argc = static_cast <int >(utf8.buf .size ());
929+ argv = utf8.ptrs .data ();
930+ }
931+ #endif
932+
897933 auto ctx_arg = common_params_parser_init (params, ex, print_usage);
898934 const common_params params_org = ctx_arg.params ; // the example can modify the default params
899935
@@ -2911,15 +2947,15 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
29112947 ).set_examples ({LLAMA_EXAMPLE_SERVER }).set_env (" LLAMA_API_KEY" ));
29122948 add_opt (common_arg (
29132949 {" --api-key-file" }, " FNAME" ,
2914- " path to file containing API keys (default: none)" ,
2950+ " path to file containing API keys, one per line; lines starting with a hash are treated as comments (default: none)" ,
29152951 [](common_params & params, const std::string & value) {
29162952 std::ifstream key_file (value);
29172953 if (!key_file) {
29182954 throw std::runtime_error (string_format (" error: failed to open file '%s'\n " , value.c_str ()));
29192955 }
29202956 std::string key;
29212957 while (std::getline (key_file, key)) {
2922- if (!key.empty ()) {
2958+ if (!key.empty () && key[ 0 ] != ' # ' ) {
29232959 params.api_keys .push_back (key);
29242960 }
29252961 }
0 commit comments