openai 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.openapi-generator/FILES +6 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +5 -0
- package/LICENSE +6 -6
- package/README.md +33 -179
- package/api.ts +2272 -0
- package/base.ts +71 -0
- package/common.ts +138 -0
- package/configuration.ts +127 -0
- package/dist/api.d.ts +1643 -0
- package/dist/api.js +1164 -0
- package/dist/base.d.ts +55 -0
- package/dist/base.js +61 -0
- package/dist/common.d.ts +65 -0
- package/dist/common.js +143 -0
- package/dist/configuration.d.ts +91 -0
- package/dist/configuration.js +54 -0
- package/dist/index.d.ts +13 -31
- package/dist/index.js +27 -193
- package/index.ts +18 -0
- package/package.json +25 -43
- package/tsconfig.json +17 -0
- package/dist/types.d.ts +0 -175
- package/dist/types.js +0 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
5.3.1
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) OpenAI (https://openai.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
|
10
10
|
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
copies or substantial portions of the Software.
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
SOFTWARE.
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,202 +1,56 @@
|
|
|
1
|
-
# OpenAI
|
|
1
|
+
# OpenAI Node.js Library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The OpenAI Node.js library provides convenient access to the OpenAI API from Node.js applications. Most of the code in this library is generated from our [OpenAPI specification](https://github.com/openai/openai-openapi).
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
**Important note: this library is meant for server-side usage only, as using it in client-side browser code will expose your secret API key. [See here](https://beta.openai.com/docs/api-reference/authentication) for more details.**
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
npm install openai
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
### Via yarn
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
yarn add openai
|
|
9
|
+
```bash
|
|
10
|
+
$ npm install openai
|
|
19
11
|
```
|
|
20
12
|
|
|
21
13
|
## Usage
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```js
|
|
26
|
-
import { OpenAI } from 'openai';
|
|
27
|
-
// or the commonJS way:
|
|
28
|
-
const { OpenAI } = require('openai');
|
|
29
|
-
|
|
30
|
-
// new OpenAI(apikey: string, organization?: string, version?: string)
|
|
31
|
-
const openai = new OpenAI(process.env.API_KEY, 'my-organization');
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Engine
|
|
35
|
-
|
|
36
|
-
Get all engines:
|
|
37
|
-
|
|
38
|
-
```js
|
|
39
|
-
const engines = await openai.getEngines();
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Get specific engine:
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
const engine = await openai.getEngine('curie');
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Completion
|
|
49
|
-
|
|
50
|
-
Make a completion:
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
const completion = await openai.complete('curie', {
|
|
54
|
-
prompt: 'Q: Hello\nA:',
|
|
55
|
-
user: 'user-123'
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
The options argument(2nd) properties follow the exactly same names as shown on official docs.
|
|
15
|
+
The library needs to be configured with your account's secret key, which is available on the [website](https://beta.openai.com/account/api-keys). We recommend setting it as an environment variable. Here's an example of initializing the library with the API key loaded from an environment variable and creating a completion:
|
|
60
16
|
|
|
61
|
-
|
|
17
|
+
```javascript
|
|
18
|
+
const { Configuration, OpenAIApi } = require("openai");
|
|
62
19
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
prompt: 'Q: Hello\nA:'
|
|
20
|
+
const configuration = new Configuration({
|
|
21
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
66
22
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Make a completion and stream the response:
|
|
23
|
+
const openai = new OpenAIApi(configuration);
|
|
70
24
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// This API may change at any time
|
|
74
|
-
const stream = await openai.completeAndStream('curie', { // or completeFromModelAndStream
|
|
75
|
-
prompt: 'Q: Hello\nA:',
|
|
76
|
-
user: 'user-123'
|
|
25
|
+
const completion = await openai.createCompletion("davinci", {
|
|
26
|
+
prompt: "Hello world",
|
|
77
27
|
});
|
|
78
|
-
|
|
79
|
-
stream.pipe(response)
|
|
28
|
+
console.log(completion.data.choices[0].text);
|
|
80
29
|
```
|
|
81
30
|
|
|
82
|
-
|
|
31
|
+
Check out the [full API documentation](https://beta.openai.com/docs/api-reference?lang=javascript) for examples of all the available functions.
|
|
83
32
|
|
|
84
|
-
|
|
85
|
-
const isSafe = (await openai.contentFilter('hi I am cool')) === 0;
|
|
86
|
-
```
|
|
33
|
+
### Request options
|
|
87
34
|
|
|
88
|
-
|
|
35
|
+
All of the available API request functions additionally contain an optional final parameter where you can pass custom [axios request options](https://axios-http.com/docs/req_config), for example:
|
|
89
36
|
|
|
90
|
-
Make a search:
|
|
91
37
|
|
|
92
|
-
```
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
38
|
+
```javascript
|
|
39
|
+
const completion = await openai.createCompletion(
|
|
40
|
+
"davinci",
|
|
41
|
+
{
|
|
42
|
+
prompt: "Once upon a time",
|
|
43
|
+
max_tokens: 5,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
timeout: 1000,
|
|
47
|
+
headers: {
|
|
48
|
+
"Example-Header": "example",
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
);
|
|
101
52
|
```
|
|
102
53
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
### Classification
|
|
54
|
+
## Thanks
|
|
106
55
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```js
|
|
110
|
-
const classification = await openai.classify({
|
|
111
|
-
examples: [
|
|
112
|
-
['A happy moment', 'Positive'],
|
|
113
|
-
['I am sad.', 'Negative'],
|
|
114
|
-
['I am feeling awesome', 'Positive']
|
|
115
|
-
],
|
|
116
|
-
labels: ['Positive', 'Negative', 'Neutral'],
|
|
117
|
-
query: 'It is a raining day :(',
|
|
118
|
-
search_model: 'ada',
|
|
119
|
-
model: 'curie'
|
|
120
|
-
});
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
The argument properties follow the exactly same names as shown on official docs.
|
|
124
|
-
|
|
125
|
-
### Answer
|
|
126
|
-
|
|
127
|
-
Answer a question:
|
|
128
|
-
|
|
129
|
-
```js
|
|
130
|
-
const answer = await openai.answer({
|
|
131
|
-
documents: ['Puppy A is happy.', 'Puppy B is sad.'],
|
|
132
|
-
question: 'which puppy is happy?',
|
|
133
|
-
search_model: 'ada',
|
|
134
|
-
model: 'curie',
|
|
135
|
-
examples_context: 'In 2017, U.S. life expectancy was 78.6 years.',
|
|
136
|
-
examples: [['What is human life expectancy in the United States?','78 years.']],
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
The argument properties follow the exactly same names as shown on official docs.
|
|
141
|
-
|
|
142
|
-
### File
|
|
143
|
-
|
|
144
|
-
Get all files:
|
|
145
|
-
|
|
146
|
-
```js
|
|
147
|
-
const files = await openai.getFiles();
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Upload a single file:
|
|
151
|
-
|
|
152
|
-
```js
|
|
153
|
-
const result = await openai.uploadFile('filename.json', await fs.readFileSync('somefile.json'), 'fine-tune');
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
Get a single file by id:
|
|
157
|
-
|
|
158
|
-
```js
|
|
159
|
-
const file = await openai.getFile('file-29u89djwq');
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
Delete a single file by id:
|
|
163
|
-
|
|
164
|
-
```js
|
|
165
|
-
await openai.deleteFile('file-29u89djwq');
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### Fine-tuning
|
|
169
|
-
|
|
170
|
-
Fine-tune from a file:
|
|
171
|
-
|
|
172
|
-
```js
|
|
173
|
-
const result = await openai.finetune({
|
|
174
|
-
training_file: 'file-29u89djwq'
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
The argument properties follow the exactly same names as shown on official docs.
|
|
179
|
-
|
|
180
|
-
Get all fine-tunes:
|
|
181
|
-
|
|
182
|
-
```js
|
|
183
|
-
const finetunes = await openai.getFinetunes();
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
Get a specific fine-tune:
|
|
187
|
-
|
|
188
|
-
```js
|
|
189
|
-
const finetune = await openai.getFinetune('ftjob-AF1WoRqd3aJ');
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
Cancel a fine-tune:
|
|
193
|
-
|
|
194
|
-
```js
|
|
195
|
-
await openai.cancelFinetune('ftjob-AF1WoRqd3aJ');
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
Get fine-tune events of a fine-tune:
|
|
199
|
-
|
|
200
|
-
```js
|
|
201
|
-
const events = await openai.getFinetuneEvents('ftjob-AF1WoRqd3aJ');
|
|
202
|
-
```
|
|
56
|
+
Thank you to [ceifa](https://github.com/ceifa) for creating and maintaining the original unofficial `openai` npm package before we released this official library!
|