@@ -200,19 +200,13 @@ void gpt_params_handle_model_default(gpt_params & params) {
200200 }
201201 params.hf_file = params.model ;
202202 } else if (params.model .empty ()) {
203- std::string cache_directory = fs_get_cache_directory ();
204- const bool success = fs_create_directory_with_parents (cache_directory);
205- if (!success) {
206- throw std::runtime_error (" failed to create cache directory: " + cache_directory);
207- }
208- params.model = cache_directory + string_split (params.hf_file , ' /' ).back ();
203+ params.model = fs_get_cache_file (string_split (params.hf_file , ' /' ).back ());
209204 }
210205 } else if (!params.model_url .empty ()) {
211206 if (params.model .empty ()) {
212207 auto f = string_split (params.model_url , ' #' ).front ();
213208 f = string_split (f, ' ?' ).front ();
214- f = string_split (f, ' /' ).back ();
215- params.model = " models/" + f;
209+ params.model = fs_get_cache_file (string_split (f, ' /' ).back ());
216210 }
217211 } else if (params.model .empty ()) {
218212 params.model = DEFAULT_MODEL_PATH;
@@ -2279,6 +2273,16 @@ std::string fs_get_cache_directory() {
22792273 return ensure_trailing_slash (cache_directory);
22802274}
22812275
2276+ std::string fs_get_cache_file (const std::string & filename) {
2277+ GGML_ASSERT (filename.find (DIRECTORY_SEPARATOR) == std::string::npos);
2278+ std::string cache_directory = fs_get_cache_directory ();
2279+ const bool success = fs_create_directory_with_parents (cache_directory);
2280+ if (!success) {
2281+ throw std::runtime_error (" failed to create cache directory: " + cache_directory);
2282+ }
2283+ return cache_directory + filename;
2284+ }
2285+
22822286
22832287//
22842288// Model utils
0 commit comments