1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use hyper_openssl::HttpsConnector;
use crate::client::Client;
/// Returns a new client for the OpenAI API.
///
/// # Arguments
/// * `api_key` - The API key to use.
///
/// # Example
/// ```
/// use openai_rs::client::Client;
/// use openai_rs::openai;
///
/// // Create the Client with your API key.
/// let client: Client = openai::new("api_key");
/// ```
pub fn new(api_key: &str) -> Client {
let hyper_client = hyper::Client::builder()
.http2_only(true)
.pool_idle_timeout(std::time::Duration::from_secs(10))
.build(HttpsConnector::new().expect("Could not create HTTPS connector"));
Client {
api_key: api_key.to_owned(),
https: hyper_client,
}
}