@@ -200,19 +200,13 @@ void gpt_params_handle_model_default(gpt_params & params) {
200
200
}
201
201
params.hf_file = params.model ;
202
202
} 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 ());
209
204
}
210
205
} else if (!params.model_url .empty ()) {
211
206
if (params.model .empty ()) {
212
207
auto f = string_split (params.model_url , ' #' ).front ();
213
208
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 ());
216
210
}
217
211
} else if (params.model .empty ()) {
218
212
params.model = DEFAULT_MODEL_PATH;
@@ -2279,6 +2273,16 @@ std::string fs_get_cache_directory() {
2279
2273
return ensure_trailing_slash (cache_directory);
2280
2274
}
2281
2275
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
+
2282
2286
2283
2287
//
2284
2288
// Model utils
0 commit comments