From 7815c52e216efe0a7855393261dd49670a858c95 Mon Sep 17 00:00:00 2001 From: jucasoliveira Date: Thu, 5 Jan 2023 21:28:15 +0000 Subject: [PATCH] add new changes to package --- bin/index.js | 23 ++++++++++++++++------- package.json | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bin/index.js b/bin/index.js index 72a5f71..d713ce2 100755 --- a/bin/index.js +++ b/bin/index.js @@ -35,12 +35,15 @@ const decrypt = (text) => { }; const saveApiKey = (apiKey) => { - fs.writeFileSync("./apiKey.txt", apiKey); + fs.writeFileSync(`${__dirname}/apiKey.txt`, apiKey); }; const getApiKey = () => { - if (fs.existsSync("./apiKey.txt")) { - const getEncryptedScript = fs.readFileSync("./apiKey.txt", "utf8"); + if (fs.existsSync(`${__dirname}/apiKey.txt`)) { + const getEncryptedScript = fs.readFileSync( + `${__dirname}/apiKey.txt`, + "utf8" + ); const decryptedScript = decrypt(getEncryptedScript); return decryptedScript; } @@ -92,7 +95,13 @@ const intro = function () { console.log(usageText); }; -const generateResponse = async (apiKey, prompt, options, response) => { +const generateResponse = async ( + apiKey, + prompt, + options, + response, + context = "" +) => { const configuration = new Configuration({ apiKey, }); @@ -101,7 +110,7 @@ const generateResponse = async (apiKey, prompt, options, response) => { const request = await openai .createCompletion({ model: options.engine || "text-davinci-002", - prompt: response.value, + prompt: `${context}\n${response.value}`, max_tokens: 2048, temperature: parseInt(options.temperature) || 0.5, }) @@ -110,10 +119,10 @@ const generateResponse = async (apiKey, prompt, options, response) => { return response; }) .catch((err) => { - console.error(`${chalk.red("Something went wront")} ${err}`); + console.error(`${chalk.red("Something went wrong")} ${err}`); }); if (!request.data?.choices?.[0].text) { - return console.error(`${chalk.red("Something went wront")}`); + return console.error(`${chalk.red("Something went wrong")}`); } // map all choices to text diff --git a/package.json b/package.json index 6ad86f9..9823e6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "terminalgpt", - "version": "1.0.2", + "version": "1.0.3", "main": "index.js", "description": "Get GPT like chatGPT on your terminal", "scripts": {