Socket
Socket
Sign inDemoInstall

openai

Package Overview
Dependencies
Maintainers
5
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openai

The official TypeScript library for the OpenAI API


Version published
Weekly downloads
2.2M
decreased by-1.31%
Maintainers
5
Weekly downloads
 
Created

What is openai?

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.

What are openai's main functionalities?

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);
});

Other packages similar to openai

FAQs

Package last updated on 05 Sep 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc