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.
@@ -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.4.0
@@ -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,7 +1,75 @@
1
- # OpenAI
1
+ # OpenAI Node.js Library
2
2
 
3
- > tl;dr: Please consider using [GPT-X](https://www.npmjs.com/package/gpt-x) instead
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 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.
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
- Enter in our community about Natural language generation to share and learn about OpenAI, prompt engineering and other providers: https://discord.gg/8ZwcSt9XkD
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).