download.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include <string>
  3. struct common_params_model;
  4. //
  5. // download functionalities
  6. //
  7. struct common_cached_model_info {
  8. std::string manifest_path;
  9. std::string user;
  10. std::string model;
  11. std::string tag;
  12. size_t size = 0; // GGUF size in bytes
  13. // return string representation like "user/model:tag"
  14. // if tag is "latest", it will be omitted
  15. std::string to_string() const {
  16. return user + "/" + model + (tag == "latest" ? "" : ":" + tag);
  17. }
  18. };
  19. struct common_hf_file_res {
  20. std::string repo; // repo name with ":tag" removed
  21. std::string ggufFile;
  22. std::string mmprojFile;
  23. };
  24. /**
  25. * Allow getting the HF file from the HF repo with tag (like ollama), for example:
  26. * - bartowski/Llama-3.2-3B-Instruct-GGUF:q4
  27. * - bartowski/Llama-3.2-3B-Instruct-GGUF:Q4_K_M
  28. * - bartowski/Llama-3.2-3B-Instruct-GGUF:q5_k_s
  29. * Tag is optional, default to "latest" (meaning it checks for Q4_K_M first, then Q4, then if not found, return the first GGUF file in repo)
  30. *
  31. * Return pair of <repo, file> (with "repo" already having tag removed)
  32. *
  33. * Note: we use the Ollama-compatible HF API, but not using the blobId. Instead, we use the special "ggufFile" field which returns the value for "hf_file". This is done to be backward-compatible with existing cache files.
  34. */
  35. common_hf_file_res common_get_hf_file(
  36. const std::string & hf_repo_with_tag,
  37. const std::string & bearer_token,
  38. bool offline);
  39. // returns true if download succeeded
  40. bool common_download_model(
  41. const common_params_model & model,
  42. const std::string & bearer_token,
  43. bool offline);
  44. // returns list of cached models
  45. std::vector<common_cached_model_info> common_list_cached_models();
  46. // resolve and download model from Docker registry
  47. // return local path to downloaded model file
  48. std::string common_docker_resolve_model(const std::string & docker);