Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding a socks example. #81

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Loading