npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gpt-x

v1.1.3

Published

Tiny OpenAI API wrapper

Downloads

69

Readme

Build Status npm License: MIT

GPT-X (Previously OpenAI)

A tiny async production-ready wrapper for OpenAI GPT-3 API.

This is an unofficial library and has no affiliations with OpenAI

Installation

Via npm

npm install gpt-x

Via yarn

yarn add gpt-x

Usage

Initialize OpenAI

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

Engine

Get all engines:

const engines = await openai.getEngines();

Get specific engine:

const engine = await openai.getEngine('curie');

Completion

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;

Search

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.

Classification

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

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.

File

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-tuning

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

Embedding

Create an embedding:

const embedding = await openai.createEmbedding('babbage-similarity', {
    input: 'Sample document text goes here'
})