char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
ee4c505a4
char/aliceai-t5-moe
1#pragma once 2 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 { 15std ::string url ; 16size_t downloaded = 0 ; 17size_t total = 0 ; 18bool cached = false; 19}; 20 21class common_download_callback { 22public : 23virtual ~common_download_callback ()= default ; 24virtual void on_start (const common_download_progress & p )= 0 ; 25virtual void on_update (const common_download_progress & p )= 0 ; 26virtual void on_done (const common_download_progress & p ,bool ok )= 0 ; 27virtual bool is_cancelled ()const {return false; } 28}; 29 30struct common_remote_params { 31common_header_list headers ; 32long timeout = 0 ;// in seconds, 0 means no timeout 33long max_size = 0 ;// unlimited if 0 34}; 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 empty 42std ::pair < std ::string ,std ::string > common_download_split_repo_tag (const std ::string & hf_repo_with_tag ); 43 44// Result of common_list_cached_models 45struct common_cached_model_info { 46std ::string repo ; 47std ::string tag ; 48std ::string to_string ()const { 49return repo + ":" + tag; 50 } 51}; 52 53// Options for common_download_file_single 54struct common_download_opts { 55std ::string bearer_token ; 56common_header_list headers ; 57bool offline = false; 58bool download_mmproj = false; 59bool download_mtp = false; 60bool download_eagle3 = false; 61bool download_dflash = false; 62bool download_dspark = false; 63common_download_callback * callback = nullptr; 64}; 65 66struct common_download_task { 67common_download_opts opts ; 68std ::string url ; 69std ::string local_path ; 70std ::function < void ()> on_done ; 71bool is_hf = false; 72 73common_download_task ()= default ; 74common_download_task (hf_cache ::hf_file f , 75const common_download_opts & opts , 76std ::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 file 83std ::vector < std ::string > common_download_get_all_parts (const std ::string & url ); 84 85// returns list of cached models 86std ::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 cache 90std ::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 path 93// returns status code or -1 on error 94// 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 , 96const std ::string & path , 97const common_download_opts & opts = {}, 98bool skip_etag = false); 99 100// resolve and download model from Docker registry 101// return local path to downloaded model file 102std ::string common_docker_resolve_model (const std ::string & docker ); 103 104// Remove a cached model from disk 105// input format: "user/model" or "user/model:tag" 106// - if tag is omitted, removes the entire repo cache directory 107// - if tag is present, removes only files matching that tag (and orphaned blobs) 108// returns true if anything was removed 109bool common_download_remove (const std ::string & hf_repo_with_tag ); 110 111struct common_download_hf_plan { 112hf_cache ::hf_file primary ; 113hf_cache ::hf_files model_files ; 114hf_cache ::hf_file mmproj ; 115hf_cache ::hf_file mtp ; 116hf_cache ::hf_file eagle3 ; 117hf_cache ::hf_file dflash ; 118hf_cache ::hf_file dspark ; 119hf_cache ::hf_file preset ;// if set, only this file is downloaded 120}; 121common_download_hf_plan common_download_get_hf_plan (const common_params_model & model ,const common_download_opts & opts );