xbasis 0.0.0-stage → 0.0.1

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,56 @@
1
+ name: Bug report
2
+ description: Create a report to help us improve
3
+ labels: ["bug"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Thanks for taking the time to fill out this bug report!
9
+ - type: textarea
10
+ id: what-happened
11
+ attributes:
12
+ label: Describe the bug
13
+ description: A clear and concise description of what the bug is, and any additional context.
14
+ placeholder: Tell us what you see!
15
+ validations:
16
+ required: true
17
+ - type: textarea
18
+ id: repro-steps
19
+ attributes:
20
+ label: To Reproduce
21
+ description: Steps to reproduce the behavior.
22
+ placeholder: |
23
+ 1. Fetch a '...'
24
+ 2. Update the '....'
25
+ 3. See error
26
+ validations:
27
+ required: true
28
+ - type: textarea
29
+ id: code-snippets
30
+ attributes:
31
+ label: Code snippets
32
+ description: If applicable, add code snippets to help explain your problem.
33
+ render: JavaScript
34
+ validations:
35
+ required: false
36
+ - type: input
37
+ id: os
38
+ attributes:
39
+ label: OS
40
+ placeholder: macOS
41
+ validations:
42
+ required: true
43
+ - type: input
44
+ id: language-version
45
+ attributes:
46
+ label: Node version
47
+ placeholder: Node v16.14.2
48
+ validations:
49
+ required: true
50
+ - type: input
51
+ id: lib-version
52
+ attributes:
53
+ label: Library version
54
+ placeholder: openai v3.0.1
55
+ validations:
56
+ required: true
@@ -0,0 +1,7 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: OpenAI support
4
+ url: https://help.openai.com/
5
+ about: |
6
+ Please only file issues here that you believe represent actual bugs or feature requests for the OpenAI Node library.
7
+ If you're having general trouble with the OpenAI API, please visit our help center to get support.
@@ -0,0 +1,20 @@
1
+ name: Feature request
2
+ description: Suggest an idea for this library
3
+ labels: ["feature-request"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Thanks for taking the time to fill out this feature request!
9
+ - type: textarea
10
+ id: feature
11
+ attributes:
12
+ label: Describe the feature or improvement you're requesting
13
+ description: A clear and concise description of what you want to happen.
14
+ validations:
15
+ required: true
16
+ - type: textarea
17
+ id: context
18
+ attributes:
19
+ label: Additional context
20
+ description: Add any other context about the feature request here.
@@ -0,0 +1,25 @@
1
+ name: Node.js CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ strategy:
15
+ matrix:
16
+ node-version: [16.x, 18.x]
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v3
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ cache: 'npm'
24
+ - run: npm ci
25
+ - run: npm run build
@@ -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
+ 6.6.0
@@ -0,0 +1,5 @@
1
+ .gitignore
2
+ README.md
3
+ git_push.sh
4
+ package.json
5
+ package-lock.json
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) OpenAI (https://openai.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # OpenAI Node.js Library
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+
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://platform.openai.com/docs/api-reference/authentication) for more details.**
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install xbasis
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ The library needs to be configured with your account's secret key, which is available in your [OpenAI account page](https://platform.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("xbasis");
19
+
20
+ const configuration = new Configuration({
21
+ apiKey: process.env.OPENAI_API_KEY,
22
+ });
23
+ const openai = new OpenAIApi(configuration);
24
+
25
+ const chatCompletion = await openai.createChatCompletion({
26
+ model: "gpt-3.5-turbo",
27
+ messages: [{role: "user", content: "Hello world"}],
28
+ });
29
+ console.log(chatCompletion.data.choices[0].message);
30
+ ```
31
+
32
+ Check out the [full API documentation](https://platform.openai.com/docs/api-reference?lang=node.js) for examples of all the available functions.
33
+
34
+ ### Request options
35
+
36
+ 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:
37
+
38
+ ```javascript
39
+ const completion = await openai.createCompletion(
40
+ {
41
+ model: "text-davinci-003",
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({
60
+ model: "text-davinci-003",
61
+ prompt: "Hello world",
62
+ });
63
+ console.log(completion.data.choices[0].text);
64
+ } catch (error) {
65
+ if (error.response) {
66
+ console.log(error.response.status);
67
+ console.log(error.response.data);
68
+ } else {
69
+ console.log(error.message);
70
+ }
71
+ }
72
+ ```
73
+
74
+ ### Streaming completions
75
+
76
+ Streaming completions (`stream=true`) are not natively supported in this package yet, but [a workaround exists](https://github.com/openai/openai-node/issues/18#issuecomment-1369996933) if needed.
77
+
78
+ ## Upgrade guide
79
+
80
+ All breaking changes for major version releases are listed below.
81
+
82
+ ### 3.0.0
83
+
84
+ - The function signature of `createCompletion(engineId, params)` changed to `createCompletion(params)`. The value previously passed in as the `engineId` argument should now be passed in as `model` in the params object (e.g. `createCompletion({ model: "text-davinci-003", ... })`)
85
+ - Replace any `createCompletionFromModel(params)` calls with `createCompletion(params)`
86
+
87
+ ## Thanks
88
+
89
+ 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).