Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
The openai npm package is a Node.js client library for accessing the OpenAI API, which provides access to powerful AI models such as GPT-3 for natural language processing tasks, including text generation, translation, summarization, and more. The package allows developers to easily integrate OpenAI's AI capabilities into their Node.js applications.
Text Completion
Generates text completions for a given prompt using the GPT-3 model.
const { Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
openai.createCompletion({
model: 'text-davinci-003',
prompt: 'Translate the following English text to French: Hello, how are you?',
max_tokens: 60
}).then(response => {
console.log(response.data.choices[0].text);
});
Text Classification
Classifies a piece of text into one of the specified categories.
const { Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
openai.createClassification({
model: 'text-davinci-003',
examples: [
['A movie about space wars and intergalactic politics', 'Science Fiction'],
['A film focusing on the love life of a New York City woman', 'Romance']
],
query: 'A story about a boy who learns he is a wizard and attends a magical school',
labels: ['Science Fiction', 'Romance', 'Fantasy']
}).then(response => {
console.log(response.data);
});
Text Summarization
Summarizes a longer piece of text into a concise version.
const { Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
openai.createCompletion({
model: 'text-davinci-003',
prompt: 'Summarize the following text: ...',
max_tokens: 60,
temperature: 0.7
}).then(response => {
console.log(response.data.choices[0].text);
});
This package provides access to IBM Watson's AI services, which include natural language processing, speech to text, text to speech, and language translation. It is similar to openai in providing AI-powered language services, but it uses IBM's Watson AI instead of OpenAI's models.
The Google Cloud npm package allows developers to interact with Google Cloud services, including its AI and machine learning services like the Natural Language API and the Translation API. It offers functionalities similar to openai but is integrated with Google's cloud ecosystem.
This package is part of Microsoft's Azure Cognitive Services and provides capabilities for speech recognition, text-to-speech, and speech translation. It offers different services compared to openai, focusing more on speech technologies rather than text-based AI models.
A tiny async production-ready wrapper for OpenAI GPT-3 API.
This is an unofficial library and has no affiliations with OpenAI
npm install openai
yarn add openai
import { OpenAI } from 'openai';
// or the commonJS way:
const { OpenAI } = require('openai');
// 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');
FAQs
The official TypeScript library for the OpenAI API
The npm package openai receives a total of 1,436,083 weekly downloads. As such, openai popularity was classified as popular.
We found that openai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.