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.
@@ -0,0 +1,6 @@
1
+ .npmignore
2
+ api.ts
3
+ base.ts
4
+ common.ts
5
+ configuration.ts
6
+ index.ts
@@ -0,0 +1 @@
1
+ 5.3.1
@@ -0,0 +1,5 @@
1
+ .gitignore
2
+ README.md
3
+ git_push.sh
4
+ package.json
5
+ package-lock.json
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- MIT License
1
+ The MIT License
2
2
 
3
- Copyright (c) 2021 Gabriel Francisco
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 all
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 THE
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
- A tiny async production-ready wrapper for [OpenAI GPT-3 API](https://beta.openai.com/docs/api-reference/introduction).
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
- **This is an unofficial library and has no affiliations with OpenAI**
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
- ### Via npm
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
- ### Initialize OpenAI
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
- Make a completion from a fine-tuned model:
17
+ ```javascript
18
+ const { Configuration, OpenAIApi } = require("openai");
62
19
 
63
- ```js
64
- const completion = await openai.completeFromModel('FINE_TUNED_MODEL', {
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
- ```js
72
- // Very experimental! Don't use on production!!!
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
- Make a content filter:
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
- ```js
85
- const isSafe = (await openai.contentFilter('hi I am cool')) === 0;
86
- ```
33
+ ### Request options
87
34
 
88
- ### Search
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
- ```js
93
- const search = await openai.search('curie', {
94
- query: 'the president',
95
- documents: [
96
- 'whitehouse',
97
- 'school',
98
- 'hospital'
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
- The options argument(2nd) properties follow the exactly same names as shown on official docs.
104
-
105
- ### Classification
54
+ ## Thanks
106
55
 
107
- Classify a document:
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!