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.8

30

index.js

@@ -11,8 +11,8 @@ #!/usr/bin/env node

// Function for generating text completions using the OpenAI API
async function generateTextCompletions(prompt) {
async function generateTextCompletions(prompt, model = 'text-davinci-002', temperature = 0.5) {
try {
const response = await axios.post(`${baseURL}/v1/text-completions`, {
prompt: prompt,
model: 'text-davinci-002',
temperature: 0.5
model: model,
temperature: temperature
}, {

@@ -26,3 +26,7 @@ headers: {

} catch (error) {
console.error(error);
if (error.response.status === 401) {
console.error('API key has not been set or is invalid. Use the "key" command to set the API key.');
} else {
console.error(error);
}
}

@@ -42,3 +46,7 @@ }

} catch (error) {
console.error('API key has not been set or is invalid. Use the "key" command to set the API key.');
if (error.response.status === 401) {
console.error('API key has not been set or is invalid. Use the "key" command to set the API key.');
} else {
console.error(error);
}
}

@@ -59,4 +67,6 @@ }

.description('Generate text completions')
.action(function (prompt) {
generateTextCompletions(prompt);
.option('-m, --model <model>', 'The model to use (default: text-davinci-002)')
.option('-t, --temperature <temperature>', 'The temperature to use (default: 0.5)')
.action(function (prompt, options) {
generateTextCompletions(prompt, options.model, options.temperature);
});

@@ -67,4 +77,6 @@

.description('Check if the API key has been set')
.action(checkAPIKey);
.action(function () {
checkAPIKey();
});
program.parse(process.argv);
program.parse(process.argv);
{
"name": "openai-text-completions",
"version": "1.0.7",
"version": "1.0.8",
"description": "A global npm package for generating text completions using the OpenAI API",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,41 +0,37 @@

# openai-text-completions
openai-text-completions
This package allows you to generate text completions using the OpenAI API from the command line.
A global npm package for generating text completions using the OpenAI API.
Prerequisites
Node.js (version 8.0 or higher)
An OpenAI API key (sign up for one here)
Installation
To install the openai-text-completions package globally:
## Installation
To install the package globally, run the following command:
Copy code
npm install -g openai-text-completions
Usage
Set the API key
Before you can use the openai-text-completions command, you need to set your API key. To do this, use the key command followed by your API key:
## Usage
To generate a text completion, run the following command:
openai-text-completions "The quick brown fox"
This will generate a text completion based on the provided prompt and the default model and temperature and print it to the terminal.
To set the API key, run the following command:
Copy code
openai-text-completions key YOUR_API_KEY
Generate text completions
To generate text completions, use the completions command followed by the prompt argument:
Copy code
openai-text-completions completions "The quick brown fox"
The prompt argument should be surrounded by quotes to ensure that it is interpreted as a single string.
By default, the completions command uses the text-davinci-002 model and a temperature of 0.5. You can modify these settings by passing additional options to the completions command. For example:
To check if the API key has been set correctly, run the following command:
Copy code
openai-text-completions completions "The quick brown fox" --model "text-davinci-002" --temperature 0.5
Check the API key
To check if the API key has been set, use the check-key command:
Copy code
openai-text-completions check-key
If the API key has been set, this command will output API key is set.. If the API key has not been set or is invalid, this command will output an error message.
## Options
- `-k, --key <key>`: Specify a new API key.
## License
This package is released under the ISC license.
License
This package is licensed under the MIT License. See the LICENSE file