Skip to content

Commit

Permalink
Adding a socks example. (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsil authored Dec 27, 2024
1 parent da3a3d2 commit 206b344
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
/examples/socks/target/
11 changes: 11 additions & 0 deletions examples/socks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
5 changes: 5 additions & 0 deletions examples/socks/README.md
Original file line number Diff line number Diff line change
@@ -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).
15 changes: 15 additions & 0 deletions examples/socks/src/main.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 206b344

Please sign in to comment.