mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-23 15:48:07 +00:00
@ -21,4 +21,4 @@ default-features = false
|
|||||||
[dependencies.minreq]
|
[dependencies.minreq]
|
||||||
version = "2"
|
version = "2"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["https-rustls", "json-using-serde"]
|
features = ["https-rustls", "json-using-serde", "proxy"]
|
||||||
|
@ -47,6 +47,7 @@ pub struct Client {
|
|||||||
pub api_endpoint: String,
|
pub api_endpoint: String,
|
||||||
pub api_key: String,
|
pub api_key: String,
|
||||||
pub organization: Option<String>,
|
pub organization: Option<String>,
|
||||||
|
pub proxy: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
@ -60,6 +61,7 @@ impl Client {
|
|||||||
api_endpoint,
|
api_endpoint,
|
||||||
api_key,
|
api_key,
|
||||||
organization: None,
|
organization: None,
|
||||||
|
proxy: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +71,17 @@ impl Client {
|
|||||||
api_endpoint: endpoint,
|
api_endpoint: endpoint,
|
||||||
api_key,
|
api_key,
|
||||||
organization: organization.into(),
|
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +95,9 @@ impl Client {
|
|||||||
if is_beta {
|
if is_beta {
|
||||||
request = request.with_header("OpenAI-Beta", "assistants=v1");
|
request = request.with_header("OpenAI-Beta", "assistants=v1");
|
||||||
}
|
}
|
||||||
|
if let Some(proxy) = &self.proxy {
|
||||||
|
request = request.with_proxy(minreq::Proxy::new(proxy).unwrap());
|
||||||
|
}
|
||||||
request
|
request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user