openai-text-completions
Advanced tools
Comparing version
30
index.js
@@ -1,11 +0,24 @@ | ||
#!/usr/bin/env node | ||
const axios = require('axios'); | ||
const { program } = require('commander'); | ||
const fs = require('fs'); | ||
// Set the API base URL and your API key | ||
const apiKeyFile = '.openai-text-completions-key'; | ||
let apiKey = 'YOUR_API_KEY'; | ||
const baseURL = 'https://api.openai.com'; | ||
// Function for generating text completions using the OpenAI API | ||
function setAPIKey(key) { | ||
apiKey = key; | ||
fs.writeFileSync(apiKeyFile, key); | ||
console.log(`API key set to ${apiKey}`); | ||
} | ||
function getAPIKey() { | ||
if (fs.existsSync(apiKeyFile)) { | ||
return fs.readFileSync(apiKeyFile, 'utf8'); | ||
} else { | ||
return apiKey; | ||
} | ||
} | ||
async function generateTextCompletions(prompt, model = 'text-davinci-002', temperature = 0.5) { | ||
@@ -20,3 +33,3 @@ try { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${apiKey}` | ||
'Authorization': `Bearer ${getAPIKey()}` | ||
} | ||
@@ -34,3 +47,2 @@ }); | ||
// Function for checking if the API key has been set | ||
async function checkAPIKey() { | ||
@@ -41,3 +53,3 @@ try { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${apiKey}` | ||
'Authorization': `Bearer ${getAPIKey()}` | ||
} | ||
@@ -55,3 +67,2 @@ }); | ||
// Set up command-line interface using Commander.js | ||
program | ||
@@ -61,4 +72,3 @@ .command('key <key>') | ||
.action(function (key) { | ||
apiKey = key; | ||
console.log(`API key set to ${apiKey}`); | ||
setAPIKey(key); | ||
}); | ||
@@ -65,0 +75,0 @@ |
{ | ||
"name": "openai-text-completions", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "A global npm package for generating text completions using the OpenAI API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4259
1.94%77
11.59%2
100%