MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / common_params_handle_model

Function common_params_handle_model

subprojects/llama.cpp/common/arg.cpp:329–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327};
328
329static handle_model_result common_params_handle_model(
330 struct common_params_model & model,
331 const std::string & bearer_token,
332 bool offline) {
333 handle_model_result result;
334 // handle pre-fill default model path and url based on hf_repo and hf_file
335 {
336 if (!model.docker_repo.empty()) { // Handle Docker URLs by resolving them to local paths
337 model.path = common_docker_resolve_model(model.docker_repo);
338 model.name = model.docker_repo; // set name for consistency
339 } else if (!model.hf_repo.empty()) {
340 // short-hand to avoid specifying --hf-file -> default it to --model
341 if (model.hf_file.empty()) {
342 if (model.path.empty()) {
343 auto auto_detected = common_get_hf_file(model.hf_repo, bearer_token, offline);
344 if (auto_detected.repo.empty() || auto_detected.ggufFile.empty()) {
345 exit(1); // error message already printed
346 }
347 model.name = model.hf_repo; // repo name with tag
348 model.hf_repo = auto_detected.repo; // repo name without tag
349 model.hf_file = auto_detected.ggufFile;
350 if (!auto_detected.mmprojFile.empty()) {
351 result.found_mmproj = true;
352 result.mmproj.hf_repo = model.hf_repo;
353 result.mmproj.hf_file = auto_detected.mmprojFile;
354 }
355 } else {
356 model.hf_file = model.path;
357 }
358 }
359
360 std::string model_endpoint = get_model_endpoint();
361 model.url = model_endpoint + model.hf_repo + "/resolve/main/" + model.hf_file;
362 // make sure model path is present (for caching purposes)
363 if (model.path.empty()) {
364 // this is to avoid different repo having same file name, or same file name in different subdirs
365 std::string filename = clean_file_name(model.hf_repo + "_" + model.hf_file);
366 model.path = fs_get_cache_file(filename);
367 }
368
369 } else if (!model.url.empty()) {
370 if (model.path.empty()) {
371 auto f = string_split<std::string>(model.url, '#').front();
372 f = string_split<std::string>(f, '?').front();
373 model.path = fs_get_cache_file(string_split<std::string>(f, '/').back());
374 }
375
376 }
377 }
378
379 // then, download it if needed
380 if (!model.url.empty()) {
381 bool ok = common_download_model(model, bearer_token, offline);
382 if (!ok) {
383 LOG_ERR("error: failed to download model from %s\n", model.url.c_str());
384 exit(1);
385 }
386 }

Callers 1

common_params_parse_exFunction · 0.85

Calls 7

common_get_hf_fileFunction · 0.85
get_model_endpointFunction · 0.85
clean_file_nameFunction · 0.85
fs_get_cache_fileFunction · 0.85
common_download_modelFunction · 0.85
emptyMethod · 0.65

Tested by

no test coverage detected