diff --git a/src/config.rs b/src/config.rs index 332a4ae..46c93e3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,6 +3,7 @@ use std::{env, io::Write, process::exit}; pub struct Config { pub api_key: String, + pub api_base: String, pub shell: String, } @@ -12,10 +13,10 @@ impl Config { println!("{}", "This program requires an OpenAI API key to run. Please set the OPENAI_API_KEY environment variable. https://github.com/m1guelpf/plz-cli#usage".red()); exit(1); }); - + let api_base = env::var("OPENAI_API_BASE").unwrap_or_else(|_| String::from("https://api.openai.com/v1")); let shell = env::var("SHELL").unwrap_or_else(|_| String::new()); - Self { api_key, shell } + Self { api_key, api_base, shell } } pub fn write_to_history(&self, code: &str) { diff --git a/src/main.rs b/src/main.rs index 58cee75..2c3c01d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,9 +29,9 @@ fn main() { let client = Client::new(); let mut spinner = Spinner::new(Spinners::BouncingBar, "Generating your command...".into()); - + let api_addr = format!("{}/completions", config.api_base); let response = client - .post("https://api.openai.com/v1/completions") + .post(api_addr) .json(&json!({ "top_p": 1, "stop": "```",