diff --git a/.gitignore b/.gitignore index 96ef6c0..282d987 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target Cargo.lock +/examples/socks/target/ diff --git a/examples/socks/Cargo.toml b/examples/socks/Cargo.toml new file mode 100644 index 0000000..b25194c --- /dev/null +++ b/examples/socks/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "socks" +version = "0.1.0" +edition = "2021" + +[dependencies] +hf-hub = { version = "0.4.0", path = "../.." } +# Adding the `socks` features automatically adds it into +# The reqwest built by hf-hub therefore enabling socks proxying. +reqwest = { version = "0.12.9", features = ["socks"] } +tokio = { version = "1.42.0", features = ["macros"] } diff --git a/examples/socks/README.md b/examples/socks/README.md new file mode 100644 index 0000000..8a228f1 --- /dev/null +++ b/examples/socks/README.md @@ -0,0 +1,5 @@ +Example showcasing socks routing. +Users simply need to add `reqwest` with proper `socks` feature enabled in order to enable it into `hf-hub`. + + +This is due to [feature unification](https://doc.rust-lang.org/cargo/reference/resolver.html#features). diff --git a/examples/socks/src/main.rs b/examples/socks/src/main.rs new file mode 100644 index 0000000..0b50768 --- /dev/null +++ b/examples/socks/src/main.rs @@ -0,0 +1,15 @@ +#[tokio::main] +async fn main() { + let _proxy = std::env::var("HTTPS_PROXY").expect("This example expects a HTTPS_PROXY environment variable to be defined to test that the routing happens correctly. Starts a socks servers and use point HTTPS_PROXY to that server to see the routing in action."); + + let api = hf_hub::api::tokio::ApiBuilder::new() + .with_progress(true) + .build() + .unwrap(); + + let _filename = api + .model("meta-llama/Llama-2-7b-hf".to_string()) + .get("model-00001-of-00002.safetensors") + .await + .unwrap(); +}