Comparing version 1.1.1 to 1.1.3
export * from './lib.js'; | ||
export * from './types.js'; |
export * from './lib.js'; | ||
export * from './types.js'; |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
@@ -0,0 +0,0 @@ import { ContentLabel, } from './types.js'; |
@@ -0,0 +0,0 @@ declare type LiteralUnion<T extends U, U = string> = T | (U & {}); |
@@ -0,0 +0,0 @@ export var ContentLabel; |
{ | ||
"name": "openai", | ||
"version": "1.1.1", | ||
"version": "1.1.3", | ||
"description": "Tiny OpenAI API wrapper", | ||
@@ -12,3 +12,4 @@ "type": "module", | ||
"lint": "eslint . --fix --cache && prettier --write src", | ||
"lint:nofix": "eslint . && prettier --check src" | ||
"lint:nofix": "eslint . && prettier --check src", | ||
"postinstall": "node ./postinstall.js" | ||
}, | ||
@@ -24,3 +25,4 @@ "repository": { | ||
"gpt", | ||
"ai" | ||
"ai", | ||
"openai" | ||
], | ||
@@ -44,4 +46,5 @@ "bugs": { | ||
"form-data": "4.0.0", | ||
"node-fetch": "3.1.0" | ||
"node-fetch": "3.1.0", | ||
"openai": "^1.1.2" | ||
} | ||
} |
203
README.md
@@ -1,204 +0,7 @@ | ||
[![Build Status](https://github.com/ceifa/openai/actions/workflows/publish.yml/badge.svg)](https://github.com/ceifa/openai/actions/workflows/publish.yml) | ||
[![npm](https://img.shields.io/npm/v/openai.svg)](https://npmjs.com/package/openai) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
# OpenAI | ||
A tiny async production-ready wrapper for [OpenAI GPT-3 API](https://beta.openai.com/docs/api-reference/introduction). | ||
> tl;dr: Please consider using [GPT-X](https://www.npmjs.com/package/gpt-x) instead | ||
**This is an unofficial library and has no affiliations with OpenAI** | ||
This package will be replaced soon by an official one from OpenAI. If you still want to use the unofficial version package, just switch to the new one called [GPT-X](https://www.npmjs.com/package/gpt-x), it will remain the same API for compatibility reasons. | ||
## Installation | ||
### Via npm | ||
```sh | ||
npm install openai | ||
``` | ||
### Via yarn | ||
```sh | ||
yarn add openai | ||
``` | ||
## Usage | ||
### Initialize OpenAI | ||
```js | ||
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'); | ||
``` | ||
### Engine | ||
Get all engines: | ||
```js | ||
const engines = await openai.getEngines(); | ||
``` | ||
Get specific engine: | ||
```js | ||
const engine = await openai.getEngine('curie'); | ||
``` | ||
### Completion | ||
Make a completion: | ||
```js | ||
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: | ||
```js | ||
const completion = await openai.completeFromModel('FINE_TUNED_MODEL', { | ||
prompt: 'Q: Hello\nA:' | ||
}); | ||
``` | ||
Make a completion and stream the response: | ||
```js | ||
const stream = await openai.completeAndStream('curie', { // or completeFromModelAndStream | ||
prompt: 'Q: Hello\nA:', | ||
user: 'user-123' | ||
}); | ||
stream.pipe(response) | ||
``` | ||
Make a content filter: | ||
```js | ||
const isSafe = (await openai.contentFilter('hi I am cool')) === 0; | ||
``` | ||
### Search | ||
Make a search: | ||
```js | ||
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: | ||
```js | ||
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: | ||
```js | ||
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: | ||
```js | ||
const files = await openai.getFiles(); | ||
``` | ||
Upload a single file: | ||
```js | ||
const result = await openai.uploadFile('filename.json', await fs.readFileSync('somefile.json'), 'fine-tune'); | ||
``` | ||
Get a single file by id: | ||
```js | ||
const file = await openai.getFile('file-29u89djwq'); | ||
``` | ||
Delete a single file by id: | ||
```js | ||
await openai.deleteFile('file-29u89djwq'); | ||
``` | ||
### Fine-tuning | ||
Fine-tune from a file: | ||
```js | ||
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: | ||
```js | ||
const finetunes = await openai.getFinetunes(); | ||
``` | ||
Get a specific fine-tune: | ||
```js | ||
const finetune = await openai.getFinetune('ftjob-AF1WoRqd3aJ'); | ||
``` | ||
Cancel a fine-tune: | ||
```js | ||
await openai.cancelFinetune('ftjob-AF1WoRqd3aJ'); | ||
``` | ||
Get fine-tune events of a fine-tune: | ||
```js | ||
const events = await openai.getFinetuneEvents('ftjob-AF1WoRqd3aJ'); | ||
``` | ||
Enter in our community about Natural language generation to share and learn about OpenAI, prompt engineering and other providers: https://discord.gg/8ZwcSt9XkD |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
408
16949
3
7
1
+ Addedopenai@^1.1.2