Skip to content

Commit

Permalink
Merge pull request #67 from supermoonie/main
Browse files Browse the repository at this point in the history
Support Proxy
  • Loading branch information
Dongri Jin authored Jan 17, 2024
2 parents e5b8778 + 9c55029 commit 5caa48b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ default-features = false
[dependencies.minreq]
version = "2"
default-features = false
features = ["https-rustls", "json-using-serde"]
features = ["https-rustls", "json-using-serde", "proxy"]
16 changes: 16 additions & 0 deletions src/v1/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct Client {
pub api_endpoint: String,
pub api_key: String,
pub organization: Option<String>,
pub proxy: Option<String>,
}

impl Client {
Expand All @@ -60,6 +61,7 @@ impl Client {
api_endpoint,
api_key,
organization: None,
proxy: None,
}
}

Expand All @@ -69,6 +71,17 @@ impl Client {
api_endpoint: endpoint,
api_key,
organization: organization.into(),
proxy: None,
}
}

pub fn new_with_proxy(api_key: String, proxy: String) -> Self {
let endpoint = std::env::var("OPENAI_API_BASE").unwrap_or_else(|_| API_URL_V1.to_owned());
Self {
api_endpoint: endpoint,
api_key,
organization: None,
proxy: Some(proxy),
}
}

Expand All @@ -82,6 +95,9 @@ impl Client {
if is_beta {
request = request.with_header("OpenAI-Beta", "assistants=v1");
}
if let Some(proxy) = &self.proxy {
request = request.with_proxy(minreq::Proxy::new(proxy).unwrap());
}
request
}

Expand Down

0 comments on commit 5caa48b

Please sign in to comment.