From 68dfc9bd3699bb632d5345054c909708493bb254 Mon Sep 17 00:00:00 2001 From: inveve Date: Fri, 28 Jul 2023 02:27:17 -0400 Subject: [PATCH 1/2] Fixed --- Cargo.toml | 3 ++- src/gpt.rs | 24 +++++++++++++++++------- src/main.rs | 5 ++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 567a342..7e8bf1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,8 @@ name = "prisma-gpt" version = "0.1.0" edition = "2021" -[bin] +[[bin]] +name = "prisma-gpt" prisma-gpt = "./src/main.rs" [dependencies] diff --git a/src/gpt.rs b/src/gpt.rs index efe566a..5fd9cad 100644 --- a/src/gpt.rs +++ b/src/gpt.rs @@ -3,21 +3,33 @@ use serde::Deserialize; use serde_json::json; use std::fmt; +const MODEL_NAME: &str = "gpt-3.5-turbo-16k"; // Define the model name here + #[derive(Deserialize, Debug)] pub struct GPTResponse { + id: String, + object: String, + created: u64, + model: String, // Model is a string choices: Vec, } #[derive(Deserialize, Debug)] pub struct Choice { - text: String, + message: Message, +} + +#[derive(Deserialize, Debug)] +pub struct Message { + role: String, + content: String, } impl fmt::Display for GPTResponse { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut choices_str = String::new(); for choice in &self.choices { - choices_str.push_str(&format!("{}\n", choice.text)); + choices_str.push_str(&format!("Role: {}, Content: {}\n", choice.message.role, choice.message.content)); } write!(f, "{}", choices_str) } @@ -45,15 +57,13 @@ impl GPTService { text: &str, ) -> Result> { let client = &self.client; - let openai_api_key = &self.openai_api_key; - let url = "https://api.openai.com/v1/completions"; + let url = "https://api.openai.com/v1/chat/completions"; let body = json!({ - "prompt": text, - "temperature": 0.7, + "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": text}], "max_tokens": 2000, - "model": "text-davinci-003", + "model": MODEL_NAME, // use the model name constant here "top_p": 1, "frequency_penalty": 0, "presence_penalty": 0, diff --git a/src/main.rs b/src/main.rs index e7ee1c8..a683a46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,12 +13,11 @@ async fn main() { .get_cleaned_schema(); let prompt = format!("{} - As a senior analyst, given the above schemas and data, write a detailed and correct Postgres sql query to answer the analytical question: + Given the above schema, write a MYSQL sql query to answer the question: {} - Comment the query with your logic. ", schema, &question); - print!("{}", &question); + print!("{}", &prompt); let openai_key = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY must be set"); From 1c520c485a0f6278603a15f130f7b62059d73a58 Mon Sep 17 00:00:00 2001 From: inveve Date: Fri, 28 Jul 2023 10:52:29 -0400 Subject: [PATCH 2/2] Update main.rs --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index a683a46..435d2e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,7 @@ async fn main() { .get_cleaned_schema(); let prompt = format!("{} - Given the above schema, write a MYSQL sql query to answer the question: - {} + As a senior analyst, given the above schemas and data, write a detailed and correct mySQL sql query to answer the analytical question: {} ", schema, &question); print!("{}", &prompt);