Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add timeout option #90

Merged
merged 1 commit into from
Jun 25, 2024
Merged
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
18 changes: 18 additions & 0 deletions src/v1/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct Client {
pub api_key: String,
pub organization: Option<String>,
pub proxy: Option<String>,
pub timeout: Option<u64>,
}

impl Client {
Expand All @@ -62,6 +63,7 @@ impl Client {
api_key,
organization: None,
proxy: None,
timeout: None,
}
}

Expand All @@ -72,6 +74,7 @@ impl Client {
api_key,
organization: organization.into(),
proxy: None,
timeout: None,
}
}

Expand All @@ -82,6 +85,18 @@ impl Client {
api_key,
organization: None,
proxy: Some(proxy),
timeout: None,
}
}

pub fn new_with_timeout(api_key: String, timeout: u64) -> 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: None,
timeout: Some(timeout),
}
}

Expand All @@ -98,6 +113,9 @@ impl Client {
if let Some(proxy) = &self.proxy {
request = request.with_proxy(minreq::Proxy::new(proxy).unwrap());
}
if let Some(timeout) = self.timeout {
request = request.with_timeout(timeout);
}
request
}

Expand Down
Loading