New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

openai-text-completions

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openai-text-completions - npm Package Compare versions

Comparing version

to
1.0.9

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",