Comparing version 0.0.4 to 0.0.5
import type { Answer, AnswerRequest, Classification, ClassificationRequest, Completion, CompletionRequest, Engine, EngineId, File, FilePurpose, FineTune, FineTuneEvent, FineTuneRequest, JsonLines, SearchDocument, SearchRequest } from './types'; | ||
export default class OpenAI { | ||
export declare class OpenAI { | ||
private readonly url; | ||
@@ -4,0 +4,0 @@ private readonly headers; |
@@ -12,2 +12,3 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OpenAI = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -116,3 +117,3 @@ const form_data_1 = tslib_1.__importDefault(require("form-data")); | ||
} | ||
exports.default = OpenAI; | ||
exports.OpenAI = OpenAI; | ||
}); |
@@ -31,2 +31,3 @@ export declare type EngineId = 'davinci' | 'curie' | 'babbage' | 'ada' | string; | ||
logit_bias?: Record<string, unknown>; | ||
user?: string; | ||
} | ||
@@ -33,0 +34,0 @@ export interface Choice { |
{ | ||
"name": "openai", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Tiny OpenAI API wrapper", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
174
README.md
@@ -1,3 +0,173 @@ | ||
Not ready for production! | ||
# OpenAI | ||
Under intensive development. | ||
A tiny async wrapper library for [OpenAI GPT-3 API](https://beta.openai.com/docs/api-reference/introduction). | ||
## 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. | ||
### 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'); | ||
``` |
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
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
15668
316
173