diff --git a/Cargo.lock b/Cargo.lock index d5f8acc..941a63a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -756,7 +756,7 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "plz" -version = "0.1.0" +version = "0.1.10" dependencies = [ "bat", "clap", diff --git a/Cargo.toml b/Cargo.toml index 15070f1..2945dd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "plz" license = "MIT" edition = "2021" -version = "0.1.0" +version = "0.1.10" readme = "README.md" categories = ["command-line-utilities"] homepage = "https://github.com/m1guelpf/plz-cli" diff --git a/README.md b/README.md index 6ffa934..ff7ad4f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ You may need to close and reopen your terminal after installation. Alternatively ## Usage -`plz` uses [GPT-3](https://beta.openai.com/). To use it, you'll need to grab an API key from [your dashboard](https://beta.openai.com/), and save it to `OPENAI_API_KEY` as follows (you can also save it in your bash/zsh profile for persistance between sessions). +`plz` uses [GPT-4o-mini](https://platform.openai.com/docs/overview). To use it, you'll need to grab an API key from [your admin api ](https://platform.openai.com/settings/organization/api-keys), and save it to `OPENAI_API_KEY` as follows (you can also save it in your bash/zsh profile for persistance between sessions). ```bash export OPENAI_API_KEY='sk-XXXXXXXX' @@ -47,6 +47,15 @@ Options: -V, --version Print version information ``` +## Model + +You can also configure the name of the model to use or change the base URL. + +```bash +export OPENAI_API_MODEL='gpt-XXXXXXXX' # Default gpt-4o-mini +export OPENAI_API_BASE='https://XXXXXXXX' # Default https://api.openai.com/v1 +``` + ## Develop Make sure you have the latest version of rust installed (use [rustup](https://rustup.rs/)). Then, you can build the project by running `cargo build`, and run it with `cargo run`. diff --git a/src/config.rs b/src/config.rs index 46c93e3..036c257 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,6 +4,7 @@ use std::{env, io::Write, process::exit}; pub struct Config { pub api_key: String, pub api_base: String, + pub api_model: String, pub shell: String, } @@ -14,9 +15,10 @@ impl Config { exit(1); }); let api_base = env::var("OPENAI_API_BASE").unwrap_or_else(|_| String::from("https://api.openai.com/v1")); + let api_model = env::var("OPENAI_API_MODEL").unwrap_or_else(|_| String::from("gpt-4o-mini")); let shell = env::var("SHELL").unwrap_or_else(|_| String::new()); - Self { api_key, api_base, shell } + Self { api_key, api_base, api_model, shell } } pub fn write_to_history(&self, code: &str) { diff --git a/src/main.rs b/src/main.rs index edbdc6a..f6e27d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,19 +29,27 @@ 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 api_addr = format!("{}/chat/completions", config.api_base); let response = client .post(api_addr) .json(&json!({ "top_p": 1, "stop": "```", "temperature": 0, - "suffix": "\n```", "max_tokens": 1000, "presence_penalty": 0, "frequency_penalty": 0, - "model": "gpt-3.5-turbo-instruct", - "prompt": build_prompt(&cli.prompt.join(" ")), + "model": config.api_model, + "messages": [ + { + "role": "system", + "content": "Return ONLY the raw script/command without any formatting, markdown, or code block indicators." + }, + { + "role": "user", + "content": build_prompt(&cli.prompt.join(" ")) + } + ], })) .header("Authorization", format!("Bearer {}", config.api_key)) .send() @@ -66,7 +74,7 @@ fn main() { std::process::exit(1); } - let code = response.json::().unwrap()["choices"][0]["text"] + let code = response.json::().unwrap()["choices"][0]["message"]["content"] .as_str() .unwrap() .trim()