Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
A tiny async production-ready wrapper for OpenAI GPT-3 API.
This is an unofficial library and has no affiliations with OpenAI
npm install gpt-x
yarn add gpt-x
import { OpenAI } from 'gpt-x';
// or the commonJS way:
const { OpenAI } = require('gpt-x');
// new OpenAI(apikey: string, organization?: string, version?: string)
const openai = new OpenAI(process.env.API_KEY, 'my-organization');
Get all engines:
const engines = await openai.getEngines();
Get specific engine:
const engine = await openai.getEngine('curie');
Make a completion:
const completion = await openai.complete('curie', {
prompt: 'Q: Hello\nA:',
user: 'user-123'
});
The options argument(2nd) properties follow the exactly same names as shown on official docs.
Make a completion from a fine-tuned model:
const completion = await openai.completeFromModel('FINE_TUNED_MODEL', {
prompt: 'Q: Hello\nA:'
});
Make a completion and stream the response:
const stream = await openai.completeAndStream('curie', { // or completeFromModelAndStream
prompt: 'Q: Hello\nA:',
user: 'user-123'
});
stream.pipe(response)
Make a content filter:
const isSafe = (await openai.contentFilter('hi I am cool')) === 0;
Make a search:
const search = await openai.search('curie', {
query: 'the president',
documents: [
'whitehouse',
'school',
'hospital'
]
});
The options argument(2nd) properties follow the exactly same names as shown on official docs.
Classify a document:
const classification = await openai.classify({
examples: [
['A happy moment', 'Positive'],
['I am sad.', 'Negative'],
['I am feeling awesome', 'Positive']
],
labels: ['Positive', 'Negative', 'Neutral'],
query: 'It is a raining day :(',
search_model: 'ada',
model: 'curie'
});
The argument properties follow the exactly same names as shown on official docs.
Answer a question:
const answer = await openai.answer({
documents: ['Puppy A is happy.', 'Puppy B is sad.'],
question: 'which puppy is happy?',
search_model: 'ada',
model: 'curie',
examples_context: 'In 2017, U.S. life expectancy was 78.6 years.',
examples: [['What is human life expectancy in the United States?','78 years.']],
});
The argument properties follow the exactly same names as shown on official docs.
Get all files:
const files = await openai.getFiles();
Upload a single file:
const result = await openai.uploadFile('filename.json', await fs.readFileSync('somefile.json'), 'fine-tune');
Get a single file by id:
const file = await openai.getFile('file-29u89djwq');
Delete a single file by id:
await openai.deleteFile('file-29u89djwq');
Fine-tune from a file:
const result = await openai.finetune({
training_file: 'file-29u89djwq'
});
The argument properties follow the exactly same names as shown on official docs.
Get all fine-tunes:
const finetunes = await openai.getFinetunes();
Get a specific fine-tune:
const finetune = await openai.getFinetune('ftjob-AF1WoRqd3aJ');
Cancel a fine-tune:
await openai.cancelFinetune('ftjob-AF1WoRqd3aJ');
Get fine-tune events of a fine-tune:
const events = await openai.getFinetuneEvents('ftjob-AF1WoRqd3aJ');
Create an embedding:
const embedding = await openai.createEmbedding('babbage-similarity', {
input: 'Sample document text goes here'
})
FAQs
Tiny OpenAI API wrapper
We found that gpt-x demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.