Skip to content

Commit

Permalink
Merge pull request #8 from jucasoliveira/change_to_nodejs
Browse files Browse the repository at this point in the history
add new changes to package
  • Loading branch information
jucasoliveira authored Jan 5, 2023
2 parents eed2227 + 7815c52 commit 410a8ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
});
Expand All @@ -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,
})
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 410a8ac

Please sign in to comment.