Skip to content

Commit c6ff5d2

Browse files
eternaphiangxson
andauthored
common: custom hf endpoint support (#12769)
* common: custom hf endpoint support Add support for custom huggingface endpoints via HF_ENDPOINT environment variable You can now specify a custom huggingface endpoint using the HF_ENDPOINT environment variable when using the --hf-repo flag, which works similarly to huggingface-cli's endpoint configuration. Example usage: HF_ENDPOINT=https://hf-mirror.com/ ./bin/llama-cli --hf-repo Qwen/Qwen1.5-0.5B-Chat-GGUF --hf-file qwen1_5-0_5b-chat-q2_k.gguf -p "The meaning to life and the universe is" The trailing slash in the URL is optional: HF_ENDPOINT=https://hf-mirror.com ./bin/llama-cli --hf-repo Qwen/Qwen1.5-0.5B-Chat-GGUF --hf-file qwen1_5-0_5b-chat-q2_k.gguf -p "The meaning to life and the universe is" * Update common/arg.cpp readability Improvement Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com> * Apply suggestions from code review --------- Co-authored-by: ベアトリーチェ <148695646+MakiSonomura@users.noreply.github.com> Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
1 parent 7a84777 commit c6ff5d2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

common/arg.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,13 @@ static void common_params_handle_model(
656656
}
657657
}
658658

659-
// TODO: allow custom host
660-
model.url = "https://huggingface.co/" + model.hf_repo + "/resolve/main/" + model.hf_file;
661-
659+
std::string hf_endpoint = "https://huggingface.co/";
660+
const char * hf_endpoint_env = getenv("HF_ENDPOINT");
661+
if (hf_endpoint_env) {
662+
hf_endpoint = hf_endpoint_env;
663+
if (hf_endpoint.back() != '/') hf_endpoint += '/';
664+
}
665+
model.url = hf_endpoint + model.hf_repo + "/resolve/main/" + model.hf_file;
662666
// make sure model path is present (for caching purposes)
663667
if (model.path.empty()) {
664668
// this is to avoid different repo having same file name, or same file name in different subdirs

0 commit comments

Comments
 (0)