From 174268261a4472bbe8d3c49a039154e3c20c5793 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 16 Dec 2022 14:25:20 +1300 Subject: [PATCH 1/2] Add a comment to tell GPT-3 which OS we're using (so it knows to run brew install vs. apt-get install, etc.) --- src/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index c43ada1..36d0077 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,23 @@ fn main() { let mut spinner = Spinner::new(Spinners::BouncingBar, "Generating your command...".into()); let client = Client::new(); + // Add a comment to tell GPT-3 what OS we're using + let os = if cfg!(target_os = "macos") { + "Mac" + } else if cfg!(target_os = "linux") { + "Linux" + } else { + "Unknown" + }; + let prompt_string = if os == "Unknown" { + format!("{}:\n```bash\n#!/bin/bash\n", cli.prompt.join(" ")) + } else { + format!( + "{}:\n```bash\n#!/bin/bash\n# OS: {}\n", + cli.prompt.join(" "), + os + ) + }; let response = client .post("https://api.openai.com/v1/completions") .json(&json!({ @@ -38,7 +55,7 @@ fn main() { "presence_penalty": 0, "frequency_penalty": 0, "model": "text-davinci-003", - "prompt": format!("{}:\n```bash\n#!/bin/bash\n", cli.prompt.join(" ")), + "prompt": prompt_string, })) .header("Authorization", format!("Bearer {}", api_key)) .send() From 627c7d84599aeeafc3b479ba81fe90e0139d839b Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Fri, 16 Dec 2022 12:51:43 +0100 Subject: [PATCH 2/2] tweak prompt --- src/main.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 36d0077..059e0ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,26 +25,17 @@ fn main() { std::process::exit(1); }); + let client = Client::new(); let mut spinner = Spinner::new(Spinners::BouncingBar, "Generating your command...".into()); - let client = Client::new(); - // Add a comment to tell GPT-3 what OS we're using - let os = if cfg!(target_os = "macos") { - "Mac" + let os_hint = if cfg!(target_os = "macos") { + " (on macOS)" } else if cfg!(target_os = "linux") { - "Linux" - } else { - "Unknown" - }; - let prompt_string = if os == "Unknown" { - format!("{}:\n```bash\n#!/bin/bash\n", cli.prompt.join(" ")) + " (on Linux)" } else { - format!( - "{}:\n```bash\n#!/bin/bash\n# OS: {}\n", - cli.prompt.join(" "), - os - ) + "" }; + let response = client .post("https://api.openai.com/v1/completions") .json(&json!({ @@ -55,7 +46,7 @@ fn main() { "presence_penalty": 0, "frequency_penalty": 0, "model": "text-davinci-003", - "prompt": prompt_string, + "prompt": format!("{}{}:\n```bash\n#!/bin/bash\n", cli.prompt.join(" "), os_hint), })) .header("Authorization", format!("Bearer {}", api_key)) .send()