Skip to content

Commit

Permalink
feat: support api base (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoxvi authored Mar 19, 2023
1 parent ebe853f commit 9d4549b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": "```",
Expand Down

0 comments on commit 9d4549b

Please sign in to comment.