Skip to content

Commit d4d915d

Browse files
authored
url: save -mu downloads to new cache location (#7826)
* url: save -mu download to new cache location * url: fs_get_cache_file_path util * url: tweak sig of fs_get_cache_file
1 parent 7a16ce7 commit d4d915d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

common/common.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ bool fs_validate_filename(const std::string & filename);
277277
bool fs_create_directory_with_parents(const std::string & path);
278278

279279
std::string fs_get_cache_directory();
280+
std::string fs_get_cache_file(const std::string & filename);
280281

281282
//
282283
// Model utils

0 commit comments

Comments
 (0)