Skip to content

Commit

Permalink
feat: Create Client with Client::default(); use default parameters (#35)
Browse files Browse the repository at this point in the history
* feat: Create Client with Client::default(); use default parameters

* update docs

Co-authored-by: Himanshu Neema <himanshun.iitkgp@gmail.com>

* update docs

Co-authored-by: Himanshu Neema <himanshun.iitkgp@gmail.com>

---------

Co-authored-by: Himanshu Neema <himanshun.iitkgp@gmail.com>
  • Loading branch information
swnb and 64bit committed Feb 11, 2023
1 parent 014ebee commit fb369e1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions async-openai/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
Completions, Embeddings, FineTunes, Models,
};

#[derive(Debug, Default, Clone)]
#[derive(Debug, Clone)]
/// Client is a container for api key, base url, organization id, and backoff
/// configuration used to make API calls.
pub struct Client {
Expand All @@ -29,15 +29,23 @@ pub const API_BASE: &str = "https://api.openai.com/v1";
/// Name for organization header
pub const ORGANIZATION_HEADER: &str = "OpenAI-Organization";

impl Client {
impl Default for Client {
/// Create client with default [API_BASE] url and default API key from OPENAI_API_KEY env var
pub fn new() -> Self {
fn default() -> Self {
Self {
api_base: API_BASE.to_string(),
api_key: std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| "".to_string()),
..Default::default()
org_id: Default::default(),
backoff: Default::default(),
}
}
}

impl Client {
/// Create client with default [API_BASE] url and default API key from OPENAI_API_KEY env var
pub fn new() -> Self {
Default::default()
}

/// To use a different API key different from default OPENAI_API_KEY env var
pub fn with_api_key<S: Into<String>>(mut self, api_key: S) -> Self {
Expand Down

0 comments on commit fb369e1

Please sign in to comment.