CoolFace
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 4d agoView on Hugging Face
0likes1.1kdownloads
download.h122 linesDownload Raw Back to common
1#pragma once2 3#include "hf-cache.h"4 5#include <string>6#include <vector>7#include <functional>8 9struct common_params_model;10 11using common_header      = std::pair<std::string, std::string>;12using common_header_list = std::vector<common_header>;13 14struct common_download_progress {15    std::string url;16    size_t downloaded = 0;17    size_t total      = 0;18    bool cached       = false;19};20 21class common_download_callback {22public:23    virtual ~common_download_callback() = default;24    virtual void on_start(const common_download_progress & p) = 0;25    virtual void on_update(const common_download_progress & p) = 0;26    virtual void on_done(const common_download_progress & p, bool ok) = 0;27    virtual bool is_cancelled() const { return false; }28};29 30struct common_remote_params {31    common_header_list headers;32    long timeout  = 0;           // in seconds, 0 means no timeout33    long max_size = 0;           // unlimited if 034};35 36// get remote file content, returns <http_code, raw_response_body>37std::pair<long, std::vector<char>> common_remote_get_content(const std::string & url, const common_remote_params & params);38 39// split HF repo with tag into <repo, tag>, for example:40// - "ggml-org/models:F16" -> <"ggml-org/models", "F16">41// tag is optional and can be empty42std::pair<std::string, std::string> common_download_split_repo_tag(const std::string & hf_repo_with_tag);43 44// Result of common_list_cached_models45struct common_cached_model_info {46    std::string repo;47    std::string tag;48    std::string to_string() const {49        return repo + ":" + tag;50    }51};52 53// Options for common_download_file_single54struct common_download_opts {55    std::string bearer_token;56    common_header_list headers;57    bool offline = false;58    bool download_mmproj  = false;59    bool download_mtp     = false;60    bool download_eagle3  = false;61    bool download_dflash  = false;62    bool download_dspark  = false;63    common_download_callback * callback = nullptr;64};65 66struct common_download_task {67    common_download_opts opts;68    std::string url;69    std::string local_path;70    std::function<void()> on_done;71    bool is_hf = false;72 73    common_download_task() = default;74    common_download_task(hf_cache::hf_file f,75            const common_download_opts & opts,76            std::function<void()> on_done = nullptr)77        : opts(opts), url(f.url), local_path(f.local_path), on_done(on_done), is_hf(true) {}78};79 80void common_download_run_tasks(const std::vector<common_download_task> & tasks);81 82// if url is a multi-part GGUF file, returns all parts, otherwise returns the single file83std::vector<std::string> common_download_get_all_parts(const std::string & url);84 85// returns list of cached models86std::vector<common_cached_model_info> common_list_cached_models();87 88// resolve the local cached file path for a HF repo without network access (hf_file, if given, must match exactly)89// returns an empty string if the model is not present in the cache90std::string common_download_resolve_path(const std::string & hf_repo_with_tag, const std::string & hf_file = "");91 92// download single file from url to local path93// returns status code or -1 on error94// skip_etag: if true, don't read/write .etag files (for HF cache where filename is the hash)95int common_download_file_single(const std::string & url,96                                const std::string & path,97                                const common_download_opts & opts = {},98                                bool skip_etag = false);99 100// resolve and download model from Docker registry101// return local path to downloaded model file102std::string common_docker_resolve_model(const std::string & docker);103 104// Remove a cached model from disk105// input format: "user/model" or "user/model:tag"106// - if tag is omitted, removes the entire repo cache directory107// - if tag is present, removes only files matching that tag (and orphaned blobs)108// returns true if anything was removed109bool common_download_remove(const std::string & hf_repo_with_tag);110 111struct common_download_hf_plan {112    hf_cache::hf_file primary;113    hf_cache::hf_files model_files;114    hf_cache::hf_file mmproj;115    hf_cache::hf_file mtp;116    hf_cache::hf_file eagle3;117    hf_cache::hf_file dflash;118    hf_cache::hf_file dspark;119    hf_cache::hf_file preset; // if set, only this file is downloaded120};121common_download_hf_plan common_download_get_hf_plan(const common_params_model & model, const common_download_opts & opts);122