Skip to content

Commit 5caa48b

Browse files
author
Dongri Jin
authored
Merge pull request #67 from supermoonie/main
Support Proxy
2 parents e5b8778 + 9c55029 commit 5caa48b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ default-features = false
2121
[dependencies.minreq]
2222
version = "2"
2323
default-features = false
24-
features = ["https-rustls", "json-using-serde"]
24+
features = ["https-rustls", "json-using-serde", "proxy"]

src/v1/api.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub struct Client {
4747
pub api_endpoint: String,
4848
pub api_key: String,
4949
pub organization: Option<String>,
50+
pub proxy: Option<String>,
5051
}
5152

5253
impl Client {
@@ -60,6 +61,7 @@ impl Client {
6061
api_endpoint,
6162
api_key,
6263
organization: None,
64+
proxy: None,
6365
}
6466
}
6567

@@ -69,6 +71,17 @@ impl Client {
6971
api_endpoint: endpoint,
7072
api_key,
7173
organization: organization.into(),
74+
proxy: None,
75+
}
76+
}
77+
78+
pub fn new_with_proxy(api_key: String, proxy: String) -> Self {
79+
let endpoint = std::env::var("OPENAI_API_BASE").unwrap_or_else(|_| API_URL_V1.to_owned());
80+
Self {
81+
api_endpoint: endpoint,
82+
api_key,
83+
organization: None,
84+
proxy: Some(proxy),
7285
}
7386
}
7487

@@ -82,6 +95,9 @@ impl Client {
8295
if is_beta {
8396
request = request.with_header("OpenAI-Beta", "assistants=v1");
8497
}
98+
if let Some(proxy) = &self.proxy {
99+
request = request.with_proxy(minreq::Proxy::new(proxy).unwrap());
100+
}
85101
request
86102
}
87103

0 commit comments

Comments
 (0)