openai 1.1.3 → 2.0.4
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 +72 -4
- package/api.ts +2481 -0
- package/base.ts +71 -0
- package/common.ts +138 -0
- package/configuration.ts +127 -0
- package/dist/api.d.ts +1816 -0
- package/dist/api.js +1228 -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 -2
- package/dist/index.js +27 -2
- package/index.ts +18 -0
- package/package.json +29 -45
- package/tsconfig.json +17 -0
- package/dist/lib.d.ts +0 -31
- package/dist/lib.js +0 -179
- package/dist/types.d.ts +0 -186
- package/dist/types.js +0 -6
- package/postinstall.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
5.4.0
|
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,7 +1,75 @@
|
|
|
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
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ npm install openai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
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:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const { Configuration, OpenAIApi } = require("openai");
|
|
19
|
+
|
|
20
|
+
const configuration = new Configuration({
|
|
21
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
22
|
+
});
|
|
23
|
+
const openai = new OpenAIApi(configuration);
|
|
24
|
+
|
|
25
|
+
const completion = await openai.createCompletion("text-davinci-001", {
|
|
26
|
+
prompt: "Hello world",
|
|
27
|
+
});
|
|
28
|
+
console.log(completion.data.choices[0].text);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Check out the [full API documentation](https://beta.openai.com/docs/api-reference?lang=node.js) for examples of all the available functions.
|
|
32
|
+
|
|
33
|
+
### Request options
|
|
34
|
+
|
|
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:
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
const completion = await openai.createCompletion(
|
|
40
|
+
"text-davinci-001",
|
|
41
|
+
{
|
|
42
|
+
prompt: "Hello world",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
timeout: 1000,
|
|
46
|
+
headers: {
|
|
47
|
+
"Example-Header": "example",
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Error handling
|
|
54
|
+
|
|
55
|
+
API requests can potentially return errors due to invalid inputs or other issues. These errors can be handled with a `try...catch` statement, and the error details can be found in either `error.response` or `error.message`:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
try {
|
|
59
|
+
const completion = await openai.createCompletion("text-davinci-001", {
|
|
60
|
+
prompt: "Hello world",
|
|
61
|
+
});
|
|
62
|
+
console.log(completion.data.choices[0].text);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error.response) {
|
|
65
|
+
console.log(error.response.status);
|
|
66
|
+
console.log(error.response.data);
|
|
67
|
+
} else {
|
|
68
|
+
console.log(error.message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Thanks
|
|
74
|
+
|
|
75
|
+
Thank you to [ceifa](https://github.com/ceifa) for creating and maintaining the original unofficial `openai` npm package before we released this official library! ceifa's original package has been renamed to [gpt-x](https://www.npmjs.com/package/gpt-x).
|