Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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`.
Expand Down
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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) {
Expand Down
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -66,7 +74,7 @@ fn main() {
std::process::exit(1);
}

let code = response.json::<serde_json::Value>().unwrap()["choices"][0]["text"]
let code = response.json::<serde_json::Value>().unwrap()["choices"][0]["message"]["content"]
.as_str()
.unwrap()
.trim()
Expand Down