MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / build_download_list

Method build_download_list

src/pull/model_downloader.cpp:287–353  ·  view source on GitHub ↗

\brief Build the download list \param model_tag the model tag \return the download list

Source from the content-addressed store, hash-verified

285/// \param model_tag the model tag
286/// \return the download list
287std::pair<nlohmann::json, float> ModelDownloader::build_download_list(const std::string& model_tag) {
288
289 nlohmann::json downloads = nlohmann::json::array();
290 float sum_file_size = 0;
291
292 try {
293 auto [new_model_tag, model_info] = supported_models.get_model_info(model_tag);
294 std::string base_url = model_info["url"];
295 std::string model_name = model_info["name"];
296 std::string file_url = model_info["file_url"];
297 std::vector<std::string> model_files = model_info["files"];
298
299 // Create model directory
300 std::string model_path = supported_models.get_model_path(new_model_tag);
301 std::filesystem::create_directories(model_path);
302
303 // GET HF api/models
304 std::string hf_response = download_utils::download_string(file_url);
305 nlohmann::json hf_model_infos = nlohmann::json::parse(hf_response);
306
307 for (const auto& filename : model_files) {
308 auto it = std::find_if(
309 hf_model_infos.begin(),
310 hf_model_infos.end(),
311 [&](const nlohmann::json& f) {
312 return f["path"] == filename;
313 }
314 );
315 if (it == hf_model_infos.end()) {
316 continue;
317 }
318
319 const auto& file = *it;
320 std::string local_path = get_model_file_path(model_path, filename);
321
322 if (!file_exists(local_path)) {
323 std::string url;
324 if (std::string(base_url).find("resolve") != std::string::npos) { // resolve provided , may from a specific branch
325 url = base_url + "/" + filename + "?download=true";
326 }
327 else {
328 url = base_url + "/resolve/main/" + filename + "?download=true";
329 }
330 bool is_lfs = file.contains("lfs");
331 std::string oid = is_lfs ? file["lfs"]["oid"] : file["oid"];
332 float file_size = static_cast<float>(file["size"]) / 1024 / 1024;
333 sum_file_size += file_size;
334
335 nlohmann::json entry = {
336 {"file", filename},
337 {"size", file_size},
338 {"url", url},
339 {"localpath", local_path},
340 {"oid", oid},
341 {"is_lfs", is_lfs},
342 };
343 downloads.push_back(entry);
344 }

Callers

nothing calls this directly

Calls 8

download_stringFunction · 0.85
parseFunction · 0.85
get_model_infoMethod · 0.80
get_model_pathMethod · 0.80
push_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected